curl命令有效,但耗时失败

问题描述 投票:-2回答:1

我正在使用以下复杂代码使用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&[email protected]&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:%[email protected]%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&[email protected]&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:%[email protected]%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查询参数,但是在某种程度上它失败了。

请告诉我,请在枪口中解决此错误。

php curl httpclient guzzle
1个回答
0
投票

更改标题后如curl一样工作正常

发件人>>

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

To

$headers = ['headers' => ['accept' => 'application/json','Access-Token' => $access_token]];
    
© www.soinside.com 2019 - 2024. All rights reserved.