鍍金池/ 問答/Python  HTML/ axios post get 方法都會(huì)先 發(fā)送 OPTIONS 我想把這個(gè) O

axios post get 方法都會(huì)先 發(fā)送 OPTIONS 我想把這個(gè) OPTIONS 驗(yàn)證去掉

由于 后端是 用的 c# Web API 2.0, 后端一直返回 405 ,后端只接受 post 請(qǐng)求,后端人員又不愿意改,
所以只能我前端用, 后端說 jQuery 的 ajax 都可以 ,憑什么 你現(xiàn)在不可以了。 后端不愿意改.

所以 問一下 大佬們 , axios 能去掉 OPTIONS 的驗(yàn)證嗎 ,不用發(fā) OPTIONS ,直接 post 請(qǐng)求。

回答
編輯回答
兔囡囡

405一般是前后臺(tái)約定的請(qǐng)求方式不同,或者后臺(tái)接口不支持你的請(qǐng)求類型吧。
如果跨域用的cors的話,可以讓后臺(tái)加個(gè)header就行

2017年9月7日 12:31
編輯回答
陌離殤

你的請(qǐng)求跨域了吧,跨域的話瀏覽器默認(rèn)自動(dòng)會(huì)先發(fā)送個(gè)options請(qǐng)求。至于怎么去掉,我也沒試過。
一般不用管,不影響post,put。
參考:
https://itbilu.com/javascript...
https://developer.mozilla.org...

2017年10月4日 23:48
編輯回答
眼雜

跨域并不一定發(fā)送options請(qǐng)求

  //針對(duì)post請(qǐng)求  
你的'Content-Type'不是'application/x-www-form-urlencoded' 或者如果有type=file的控件就    
是'multipart/form-data' 或者服務(wù)端或者你本身有自定義content-type的話 倆者不統(tǒng)一,瀏覽器才
會(huì)先發(fā)送options請(qǐng)求!

**建議你看看你們直接form-data接受的值格式的統(tǒng)一性**
2017年12月31日 15:25
編輯回答
扯不斷

跨域并滿足以下條件,瀏覽器就會(huì)發(fā)送OPTIONS請(qǐng)求:

  • It uses methods other than GET, HEAD or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, ortext/plain, e.g. if the POST request sends an XML payload to the server using application/xmlor text/xml, then the request is preflighted.
  • It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)
2018年8月24日 10:14