Axios 跨域请求只请求了一次

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013253924/article/details/81773089

Axios跨域请求应该请求两次,第一次请求到服务器,请求的类型是OPTIONS

Request Method:

OPTIONS

如果后端解决了跨域请求,后端服务器应该在返回头里加上以下几个参数

Access-Control-Allow-Origin:*

Access-Control-Allow-Headers:x-requested-with,content-type,X-Token,x-custom-header,Accept,Authorization,other_header,x-csrf-token,Authentication

Access-Control-Allow-Methods: POST,GET,PUT,DELETE,PATCH,OPTIONS

Content-Type:text/html; charset=UTF-8

如果还是只有一个请求的话,可以尝试修改Content-Type

这个参数改成:

application/x-www-form-urlencoded; charset=UTF-8

猜你喜欢

转载自blog.csdn.net/u013253924/article/details/81773089
今日推荐