Curl请求如何向Axios请求?


curl -H "Authorization: Token token=sfg999666t673t7t82" -H "Content-Type: application/json" -d '{"phone_call": { "call_direction": true, "targetable_type": "contact", "targetable": { "id": "1", "first_name": "Jane", "last_name": "Sampleton (sample)", "work_number ":"5304915427", "mobile_number ":"11919457004 " }, "note ": { "description": "Sample note"} }}' -X POST https://domain.myfreshworks.com/crm/sales/api/phone_calls

当你做这个请求时,你成功地得到了响应,但你只是想和axios做同样的请求。我该怎么做呢?我试了一下,但不工作,因为'a cors错误。


const headers = {
'Content-Type': 'application/json',
Authorization: 'Token sfg999666t673t7t82',
};
var dataString =
'{"phone_call": { "call_direction": true, "targetable_type": "contact", "targetable": { "id": "1", "first_name": "Jane", "last_name": "Sampleton (sample)", "work_number ":"5304915427", "mobile_number ":"11919457004 " }, "note ": { "description": "Sample note"} }}';
Axios.post('https://domain.myfreshworks.com/crm/sales/api/phone_calls', dataString, {
headers: headers,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
``

标题在您的axios版本中似乎不正确。

Authorization: Token token=sfg999666t673t7t82Authorization: 'Token sfg999666t673t7t82'不一样。

尝试将Authorization: 'Token sfg999666t673t7t82'更改为Authorization: 'Token token=sfg999666t673t7t82',以便请求相等。