像这样的带有 curl 的查询可以正常工作:
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 请求无法在此处编写代码:
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"
被忽略了,但为什么呢?