http pre-request options

 

 

In there are many cases, when we call a ajax request js inside, but there in the browser queries to request twice, the first time the Request Method parameters are OPTIONS, and once that is our real request, such as get or post requests embodiment

After reviewing relevant information discovery, this is a way to deal with the complex cross-domain browser request, before actually sending the request, will carry out a pre-request, it is what we just said parameters for the first time the OPTIONS request, his role is a tentative server response is correct, that is, whether to accept a real request, if acquired after the options in response to the request is rejected in nature, such as 500, etc. http status, it will stop a second time access real request

 

Generally explain that there are three ways to cause this behavior:

1: The method of the request is not GET / HEAD / POST

2: POST request is not a Content-Type application / x-www-form-urlencoded, multipart / form-data, or text / plain

3: request sets a custom header field

For example, My My Content-Type set to "application / json; charset = utf -8" and a custom header option led to this situation.
Disclaimer: This article is CSDN bloggers - the original article "Blue front", following the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/kahhy/article/details/81563063

Guess you like

Origin www.cnblogs.com/mzdljgz/p/11412429.html