我得到一个状态码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>
);
}