The problem that headers [‘content-type ‘] does not work is set in the Axios get method request interface

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: