After axios creates an instance, the put request cannot carry the set request header.

after creating the axios instance code, the post,put, is set and the common request header application/x-www-form-urlencoded;charset=UTF-8. is set. The request using post carries a custom-set request header, but after using put, the request does not carry the set request header. And there is a cross-domain problem. The
code is as follows:

const instance = axios.create({
baseURL: process.env.BASE_API,
timeout: 5000,
withCredentials: true,
headers: {
"content-type": "application/x-www-form-urlencoded;charset=UTF-8"
}
})

function put (url, putData) {
return instance.put(url, qs.stringify(putData))
}

function post (url, postData) {
 return instance.post(url, qs.stringify(postData))
}

export default {
 get: get,
 post: post,
 put: put
}

request for post
clipboard.png
put
clipboard.png

Mar.15,2021

I guess the request header is also set in the post,put method encapsulated by axios. Try the method without encapsulation. Try


this is not the put request header is the options request header
when the request is put so it is not a simple request to send a pre-checked options request
to see a field Access-Control-Request-Method: PUT that is to ask the server whether the server supports PUT cross-domain requests < / Does not belong to simple request , The browser will send an options, to inquire about the server

first.
Menu