簡體   English   中英

curl 命令有效,但 guzzle 失敗

[英]curl command works but guzzle failed

我正在使用下面的 guzzle 代碼使用 Odoo API 創建客戶

$headers = ['headers' => ['Accept' => 'application/json','Content-Type'     => 'application/json','Access-Token' => $access_token]];
$client = new \GuzzleHttp\Client($headers);                
$response = $client->request('POST', $url.'?magento_id='.$magento_id.'&odoo_email='.$magento_email.'&data_json='.json_encode($magentoCustomer));
echo $response->getStatusCode();exit;

但我在錯誤日志中收到以下錯誤

error: `POST https://domain/api/res.partner/magento_update_partner_single?magento_id=28&odoo_email=mail@mail.com&data_json=%7B%22customer%22:%7B%22id%22:28,%22group_id%22:1,%22created_in%22:%22Default%20Store%20View%22,%22dob%22:%22string%22,%22email%22:%22mail@mail.com%22,%22firstname%22:%22Bilal%22,%22lastname%22:%22Usean%22,%22middlename%22:%22%22,%22store_id%22:1,%22website_id%22:1,%22addresses%22:%5B%7B%22id%22:113,%22customer_id%22:28,%22country_id%22:%22US%22,%22street%22:%5B%227000%20Central%20Parkway,%20Suite%20220%22%5D,%22telephone%22:%22+1%20678-648-7722%22,%22postcode%22:%2230328%22,%22city%22:%22Atlanta%22,%22region%22:%7B%22region_code%22:%22GA%22%7D,%22firstname%22:%22Bilal%20Usean%22,%22lastname%22:%22Bilal%20Usean%22,%22middlename%22:%22%22%7D%5D,%22disable_auto_group_change%22:0%7D,%22password%22:%22qwer@123%22%7D` resulted in a `400 BAD REQUEST` response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Invalid J (truncated...)

我已經從錯誤中復制了 URL 並使用以下命令運行,我得到 HTTP 狀態代碼 200 成功響應。

curl -X POST 'https://domain/api/res.partner/magento_update_partner_single?magento_id=28&odoo_email=mail@mail.com&data_json=%7B%22customer%22:%7B%22id%22:28,%22group_id%22:1,%22created_in%22:%22Default%20Store%20View%22,%22dob%22:%22string%22,%22email%22:%22mail@mail.com%22,%22firstname%22:%22Bilal%22,%22lastname%22:%22Usean%22,%22middlename%22:%22%22,%22store_id%22:1,%22website_id%22:1,%22addresses%22:%5B%7B%22id%22:113,%22customer_id%22:28,%22country_id%22:%22US%22,%22street%22:%5B%227000%20Central%20Parkway,%20Suite%20220%22%5D,%22telephone%22:%22+1%20678-648-7722%22,%22postcode%22:%2230328%22,%22city%22:%22Atlanta%22,%22region%22:%7B%22region_code%22:%22GA%22%7D,%22firstname%22:%22Bilal%20Usean%22,%22lastname%22:%22Bilal%20Usean%22,%22middlename%22:%22%22%7D%5D,%22disable_auto_group_change%22:0%7D,%22password%22:%22qwer@123%22%7D' -g -H "accept: application/json" -H "Access-Token: df729ade753cbe46789befae12344d72e9a7964d"

curl 命令工作正常,因此 URL 查詢參數已正確傳遞,但不知何故它在 guzzle 中失敗了。

請建議我在 guzzle 中修復此錯誤。

像 curl 一樣更改 header 后工作正常

$headers = ['headers' => ['Accept' => 'application/json','Content-Type'     => 'application/json','Access-Token' => $access_token]];

$headers = ['headers' => ['accept' => 'application/json','Access-Token' => $access_token]];

暫無
暫無

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

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