开发者

How do I submit a JSON to SOLR using Zend_Client?

开发者 https://www.devze.com 2023-04-07 20:58 出处:网络
How do I submit a JSON to SOLR using Zend_Client? Assume the JSON I am using is (It was taken from the SOLR WIKI, so I assume it is right).

How do I submit a JSON to SOLR using Zend_Client?

Assume the JSON I am using is (It was taken from the SOLR WIKI, so I assume it is right).

$JSON ='[{"id" : "3", "title" : "test3","description":"toottoto totot ototot "}]';

I see no error in the solr error log, this is the code I use to submit DOES NOT WORK

$url = 'http://localhost:8983/solr/update/json';
$Client = new Zend_Http_Client($url);
$Client->resetParameters();
$Client->setMethod(Zend_Http_Client::POST);
$Client->setHeaders('Content-type','application/json');
$Client->setParameterPost($JSON);//***** WRONG *****
    $Client->setRawData($JSON); //* **** RIGHT FROM ANSWER BELOW, STILL NEED TO ENCODE IT!
$response = $Client->request();

THI开发者_StackOverflowS WORKS FROM THE COMMAND LINE!

sudo curl http://localhost:8983/solr/update/json -H 'Content-type:application/json' -d '
[{"id" : "3", "title" : "test3","description":"toottoto totot ototot "}]'


The setParameterPost() method takes two arguments, the parameter name and its value like this:

$client->setParameterPost('name', 'john'); // results in name=john

Try using setRawData() instead, this will let you set raw post data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号