fix(http-client): delete Content-Type in request interceptor when data is FormData

Instance-level default Content-Type: application/json was overriding
browser's auto-generated multipart/form-data boundary. Remove it for
FormData so browser sets correct Content-Type with boundary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-06 11:03:00 -08:00
parent fc85983b43
commit dca2031a38
1 changed files with 4 additions and 1 deletions

View File

@ -20,7 +20,7 @@ class HttpClient {
headers: { 'Content-Type': 'application/json' },
});
// Request 拦截器:注入 Bearer token
// Request 拦截器:注入 Bearer tokenFormData 时删除 Content-Type 让浏览器自动带 boundary
this.client.interceptors.request.use((config) => {
if (typeof window !== 'undefined') {
try {
@ -35,6 +35,9 @@ class HttpClient {
// ignore parse errors
}
}
if (config.data instanceof FormData) {
delete config.headers['Content-Type'];
}
return config;
});