簡體   English   中英

Axios post 請求失敗,狀態碼為 400

[英]Axios post request failed with status code 400

我收到以下請求的狀態代碼 400,但它在郵遞員中工作正常。

function App() {
  function sendRequest(){
    let body={
        client_id: 'val1',
        client_secret: 'val2',
        code: '12345',
        grant_type: 'authorization_code',
        redirect_uri: 'exp://127.0.0.1:19000'
    };
    let config = {
      headers:{
        'Content-Type': 'application/x-www-form-urlencoded',
      }
    }
    axios.post('https://www.example.com',body,config).then((res)=>{
      console.log("The response is: "+res)
    }).catch(err=>console.log("The error is: "+err))
  }

  return (
    <div className="App">
     <button onClick={()=>sendRequest()} >Run</button>
    </div>
  );
}

這是我得到的控制台上的輸出, The error is: Error: Request failed with status code 400

試試這個方法:

function App() {
      function sendRequest(){
        let params =new URLSearchParams();
        params.append('client_id','val1');
        params.append('client_secret','val2');
        params.append('code','12345');
        params.append('grant_type','authorization_code');
        params.append('redirect_uri','exp://127.0.0.1:19000');
        axios.post('https://www.example.com',params).then((res)=>{
          console.log("The response is: "+res)
        }).catch(err=>console.log("The error is: "+err))
      }
    
      return (
        <div className="App">
         <button onClick={()=>sendRequest()} >Run</button>
        </div>
      );
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM