如何使用 Zend_Client 向 SOLR 提交 JSON?
如何使用 Zend_Client 向 SOLR 提交 JSON?
假设我正在使用的 JSON 是(它取自 SOLR WIKI,所以我认为它是正确的)。
$JSON ='[{"id" : "3", "title" : "test3","description":"toottoto totot ototot "}]';
我在solr错误日志中没有看到错误,这是我用来提交的代码 不起作用,
$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();
这可以从命令行运行!
sudo curl http://localhost:8983/solr/update/json -H 'Content-type:application/json' -d '
[{"id" : "3", "title" : "test3","description":"toottoto totot ototot "}]'
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();
THIS 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 "}]'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setParameterPost() 方法采用两个参数,参数名称及其值,如下所示:
$client->setParameterPost('name', 'john'); // 结果为 name=john
尝试使用 setRawData() 相反,这将允许您设置原始发布数据。
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.