【发布时间】:2021-10-18 17:11:01
【问题描述】:
我收到以下请求的状态码 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
【问题讨论】:
-
` 'Content-Type': 'application/json' ` 请尝试使用 contet-type application json。
-
另一个常见的错误可能是:在邮递员上,您正在执行
post或get? -
你确定要发送给
example.com吗?如果您拥有服务器代码,您也应该在此处发布它。否则,请告诉我们您的目标是什么?
标签: javascript reactjs axios