改Content-Type 避免预请求问题

https://developer.mozilla.org...

上面说 Content-Type可以表示客户端告诉服务端实际发送的数据类型,如果我发送的实际数据是json格式,但是Content-Type设置成其他的(比如:application/x-www-form-urlencoded, multipart/form-data),是不是也能避免option预请求?

不修改时:

图片描述

改为'Content-Type': 'application/x-www-form-urlencoded'后就没有options了:

const instance = axios.create({
  timeout: 15000,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  // cancelToken: source.token
});

图片描述

阅读 7.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题