狂饮发送原始帖子请求 - php

我正在使用Guzzle3(v3.9.3)的项目上工作,我想知道如何发送原始的发帖请求,我已经尝试过这些解决方案,但没有一个适合我。我正在使用这个Guzzle3 manual。

解决方案:

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

$body = '{"filter_":{"user":{"email":"[email protected]"}}}';
$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":"[email protected]"}}}';

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

$req->setBody($body);
$response = json_decode($client->send($req)->getBody(true)); 

他们都没有为我工作

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

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

...
$body = array(
'filter_' => array(
   'user' => array( "email" => $email )
 )
);

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

在邮递员处,对WS的呼叫工作。

提前致谢

参考方案

我要发布响应以防万一有人需要,我不得不将所有块放在try catch之间

try{
$client = new Client();
$client->setDefaultOption('headers', array(
'Authorization' =>  'Bearer '.$token,
));
$body = '{"filter_":{"user":{"email":"[email protected]"}}}';
$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);
}

PHP JQuery复选框 - php

我有以下片段。 var myData = { video: $("input[name='video[]']:checked").serialize(), sinopse: $("#sinopse").val(), dia: $("#dia").val(), quem: $(&#…

转义字符无法正常工作 - php

我试图在PHP中创建html内容,并且为onclick事件提供了一个名为uchat的div函数。该函数采用一个字符串的名称参数。如下所示:$name = "Php string"; $echostr .= "<div onClick='uchat(\'$name\')'> &l…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…