Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php cUrl中的请求在CLI上工作-但在HTTP中失败_Php_Curl_Guzzle_Http Status Code 400 - Fatal编程技术网

Php cUrl中的请求在CLI上工作-但在HTTP中失败

Php cUrl中的请求在CLI上工作-但在HTTP中失败,php,curl,guzzle,http-status-code-400,Php,Curl,Guzzle,Http Status Code 400,我能够成功地执行如下cUrl命令(api密钥已删除): 但是,当我尝试在GuzzleHTTP中构造相同的请求时,我得到了回报: 客户端错误:POSThttp://api.url.example/api/inquiries 导致400个错误的请求响应:{“代码”:400,“消息”:“未知错误”。} 我也看到过其他类似的帖子,但遵循他们的决议并没有给我带来任何成功 下面是抛出400错误的GuzzleHTTP请求。getHeaders函数返回一个关联数组,getBody函数返回一个json字符串(在关

我能够成功地执行如下cUrl命令(api密钥已删除):

但是,当我尝试在GuzzleHTTP中构造相同的请求时,我得到了回报:

客户端错误:POSThttp://api.url.example/api/inquiries 导致400个错误的请求响应:{“代码”:400,“消息”:“未知错误”。}

我也看到过其他类似的帖子,但遵循他们的决议并没有给我带来任何成功

下面是抛出400错误的GuzzleHTTP请求。
getHeaders
函数返回一个关联数组,
getBody
函数返回一个json字符串(在关联数组上调用
json\u encode

我已经使用中间件确认Guzzle生成的头与上面在CLI cUrl请求中列出的头相同

有什么想法吗?关于我可以调查以调试的其他细节的想法


听起来您的请求并不是您认为(或希望)要发送的。比较curl和Guzzle的最简单方法是在您的请求或Guzzle客户端实例化中启用调试请求参数<代码>$client=new-GuzzleHttp\client(['debug'=>true,])
$response=$client->post($url,['debug'=>true,])听起来您的请求不是您认为(或希望)要发送的。比较curl和Guzzle的最简单方法是在您的请求或Guzzle客户端实例化中启用调试请求参数<代码>$client=new-GuzzleHttp\client(['debug'=>true,])
$response=$client->post($url,['debug'=>true,])
curl --request POST 'http://api.url.example/api/inquiries' \
--header 'User-Agent: GuzzleHttp' \
--header 'Host: api.url.example' \
--header 'Api-Key: API-KEY' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Accept-Encoding: gzip, deflate, br' \
--data-raw '{
    "AgentID": null,
    "Message": "test"
}'
$client = new \GuzzleHttp\Client();

try {
    $rsp = $client->post(
        $this->LEAD_URL,
        [
            'headers' => $this->getHeaders(),
            'body'    => $this->getBody()
        ]
    );
} catch (GuzzleHttp\Exception\RequestException $e) {
    throw new Exception('Unable to connect to' + $this->LEAD_URL, 400, $e);
}