2014-12-07 93 views
2

与卷曲的查询,像这样的,做工精细:HTTP_Request2 POST参数被忽略?

curl -XPOST -H "Content-Type: application/json" -d '{"query":"porges","start":0,"rows":10,"lang":"ENGLISH"}' http://localhost:8080/services/rest/index/z56508/search/field/search 

我我的情况,我得到11次命中那里。但是,当我尝试将其转换为HTTP_Request2时,该调用将返回数据库中的所有匹配。

我已经看过Http_Request2 POST request not working到这里写代码:

require_once 'HTTP/Request2.php'; 
    $url = "http://localhost:8080/services/rest/index/z56508/search/field/search"; 
    $data = array("query"=>"porges","start"=>"0","rows"=>"10","lang"=>"ENGLISH"); 

    $r = new HTTP_Request2($url); 
    $r->setHeader('Content-Type', 'application/json;charset=UTF-8'); 
    $r->setMethod(HTTP_Request2::METHOD_POST) 
      ->addPostParameter($data); 
    $response = $r->send(); 
    $body = $response->getBody(); 
    echo $body; 

我在做什么错?好像"query" => "porges"被忽略,但为什么?

回答