最近在工作中,遇到了跨域请求的问题,其中有的请求用到了option欲请求,所以今天总结一下。
跨域请求出现options请求的原因:
Unlike “simple requests” (discussed above), "preflighted" requests first send an HTTP request by the
OPTIONS
method to the resource on the other domain, in order to determine whether the actual request is safe to send
翻译过来就是:复杂跨域请求,首先会发送一个options请求来决定真正的请求是否足够安全。
那么如果区分简单请求以及复杂请求就比较关键了,下面是几个关键的点:
method
- GET
- POST
- HEAD
headers
- Accept
- Accept-Language
- Content-Language
- Content-Type
其中 content-type 值只包括
- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
网友评论