簡體   English   中英

Curl Request 到 Axios Request 怎么辦?

[英]Curl Request to Axios Request how?

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 發出相同的請求。 我怎樣才能做到這一點 ? 我嘗試了這個但不起作用我得到了一個 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'以便請求是等效的。

暫無
暫無

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

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