Php Guzzle3发送原始Post请求

Php Guzzle3发送原始Post请求,php,guzzle,Php,Guzzle,我正在从事使用Guzzle3(v3.9.3)的项目,我想知道如何发送原始post请求,我尝试过这些解决方案,但没有一个对我有效。我在用这个大嘴巴 解决方案: $client = new Client(); $client->setDefaultOption('headers', array( 'Authorization' => 'Bearer '.$token, 'Accept' => 'application/json' )); $body = '{"filter_":

我正在从事使用Guzzle3(v3.9.3)的项目,我想知道如何发送原始post请求,我尝试过这些解决方案,但没有一个对我有效。我在用这个大嘴巴

解决方案:

$client = new Client();
$client->setDefaultOption('headers', array(
'Authorization' =>  'Bearer '.$token,
'Accept' => 'application/json'
));

$body = '{"filter_":{"user":{"email":"aaa@test.com"}}}';
$req = $client->post($url, array(), $body,
array(
 'cert' => array($certification, 'password'),
)
);
$response = json_decode($client->send($req)->getBody(true)); 
解决方案2:

$client = new Client();
$client->setDefaultOption('headers', array(
 'Authorization' =>  'Bearer '.$token,
'Accept' => 'application/json'
));

$body = '{"filter_":{"user":{"email":"aaa@test.com"}}}';

$req = $client->post($url, array(), array(),
 array(
    'cert' => array($certification, 'password'),
 )
);

$req->setBody($body);
$response = json_decode($client->send($req)->getBody(true)); 
他们都不为我工作

错误:找不到客户端错误响应[状态代码]404[原因短语][url]

我尝试了一些在互联网上找到的解决方案(但对于Guzzle6),它可以工作,但我没有得到正确的结果(它没有考虑我发送的过滤器,即邮件地址,所以我得到了所有结果)

在邮递员的电话工作


提前感谢

我正在发布回复,以防有人需要,我不得不在try-catch之间加入所有团队

try{
$client = new Client();
$client->setDefaultOption('headers', array(
'Authorization' =>  'Bearer '.$token,
));
$body = '{"filter_":{"user":{"email":"aaa@test.com"}}}';
$req = $client->post($url, array(), $body,
array(
 'cert' => array($certification, 'password'),
)
);
$response = json_decode($client->send($req)->getBody(true)); 
catch(Guzzle\Http\Exception\BadResponseException $e){
        $response = json_decode($e->getResponse()->getBody(),true);
}

有没有理由限制你大吃大喝?您能否提供有关如何配置邮递员请求的更多信息?(如果可以在Postman中完成,就可以在Guzzle中完成。)你说,捕获异常并将其作为正确的数据进行解码是一个解决方案吗?当WS返回空响应时,我得到了我提到的错误,当我添加带有BadResponseException的bloc catch并调试$e时,我看到我得到了空响应!!
try{
$client = new Client();
$client->setDefaultOption('headers', array(
'Authorization' =>  'Bearer '.$token,
));
$body = '{"filter_":{"user":{"email":"aaa@test.com"}}}';
$req = $client->post($url, array(), $body,
array(
 'cert' => array($certification, 'password'),
)
);
$response = json_decode($client->send($req)->getBody(true)); 
catch(Guzzle\Http\Exception\BadResponseException $e){
        $response = json_decode($e->getResponse()->getBody(),true);
}