鍍金池/ 問答/HTML/ axios 報錯

axios 報錯

      this.axios({
        method: 'POST',
        url: URL,
        data: {
          "mobile": "18658163306",
        },
        headers: {
          'appId': 1000000,
          'Content-Type' : 'application/json',
        }
      })
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
  這樣寫報錯,這樣寫請求頭報錯,請問怎么寫
  
  
  

clipboard.png

回答
編輯回答
赱丅呿

'Content-Type'設(shè)置成'application/json'會導(dǎo)致跨域,一般情況會先觸發(fā)瀏覽器的OPTIONS請求。
所以,服務(wù)器端必須設(shè)置Access-Control-Allow-Headers。

2017年5月1日 04:27
編輯回答
懶豬

403 這個你要跟你們寫后端的人反映下,他會處理這個問題。
如果這不是你們自己的后端,而是你想用別的站點的接口,恐怕人家是不給用喲

2017年8月13日 16:39
編輯回答
旖襯

clipboard.png
{post,put直接寫這里}
如果每個請求都加的話,那就在axios.interceptors.request.use((config) => {
里面寫

2017年6月29日 21:25
編輯回答
涼汐

header中appId不是標(biāo)準(zhǔn)中的header會導(dǎo)致發(fā)起option請求, 需要服務(wù)端配置

add_header Access-Control-Allow-Methods 'GET,POST,OPTIONS';
add_header Access-Control-Allow-Headers 'App-User-Agent, App-IDENTIFIER';//加上自定義的header

http://www.ruanyifeng.com/blo...

2017年7月25日 23:11
編輯回答
青檸

post方法應(yīng)該是直接傳對象,不是params吧,是不是這個報的錯

2018年1月9日 02:43