The request headers are set in the Axios wrapper request method and are not present in the Request Headers
service.interceptors.request.use(
config => {
config.data = JSON.stringify(config.data);
config.headers['Authorization'] = getToken();
config.headers['Content-Type'] = "application/json;charset=utf-8";
return config;
},
error => {
return Promise.reject();
}
);
The Axios source code under NPM removes the Content-Type setting when RequestData is not set
// Add headers to the request
if ('setRequestHeader' in request) {
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
// Remove Content-Type if data is undefined
delete requestHeaders[key];
} else {
// Otherwise add header to the request
request.setRequestHeader(key, val);
}
});
}
Solution:
If (typeof requestData === ‘undefined’ & & Key.tolowerCase () === ‘Content-Type ‘)
2. Assign config.data = true to requestData
service.interceptors.request.use(
config => {
config.data = JSON.stringify(config.data);
config.headers['Authorization'] = getToken();
config.data = true
config.headers[ 'Content-Type'] = "application/json;charset=utf-8";
return config;
},
error => {
return Promise.reject();
}
);
Reference data: https://blog.csdn.net/qq_24729895/article/details/80367460
Read More:
- Encapsulation of Axios and management of API interface in Vue
- Solve the problem that the delete request is not available under SpringBoot. There was an unexpected error (type=Method Not Allowed, status=405).
- IIS “Bad Request – Request Too Long. HTTP Error 400. The size of the request headers is too long.”
- can’t set headers after they are sent
- Solve the problem of request method ‘get’ not supported
- Solution of Vue axios400 bad request problem
- Bad Request – Request Too Long. HTTP Error 400. The size of the request headers is too long
- [idea] error occurred when using @ data annotation in Lombok: no related get / set method was found
- Error domain = nsurlerrordomain code = – 1001 “request timeout occurred in swift alamofire get request. ” UserInfo={NSUnderlyingErro
- How to solve the cross domain problem of Axios in Vue project
- Four ways to get Django parameters in request
- Centos-7 set boot to enter the text interface (not enter the graphical interface)
- When feign is called, the solution of request method ‘post’ not supported appears
- TypeError: Failed to execute ‘fetch‘ on ‘Window‘: Request with GET/HEAD method cannot have body.
- Flash + Vue uses Axios to obtain server data, and reports error: “request aborted”
- To solve the problem of C # calling excel interface error, prompt: the COM object of Microsoft. Office. Interop. Excel. Applicationclass is forcibly converted to the interface type “Microsoft. Offi”
- UnhandledPromiseRejectionWarning Error: Can‘t set headers after they are sent (How to Fix)
- Pull is not possible because you have unmerged files. Please, fix them up in the work tree, and then
- Solve the problem that power view in Excel prompts activate method of oleobject class failed or activate method like oleobject is invalid
- GeTx reports an error in the get request using getconnect