CouchDB 1.0.2 http_post_data 从 PHP Pecl 错误内容类型查看
首先,这是我当前的系统:
- CouchDB 1.0.2
- PHP 5.3.6
- Apache httpd 2.2.19
- PECL http 1.7.1
- CouchDB-Lucene 0.6.1
我正在使用 CouchDB 和 CouchDB-Lucene 构建一个迷你搜索引擎。当用户输入查询时,我 POST 到 PHP 脚本,然后该脚本查询 couchdb-lucene。然后,Couchdb-lucene 将向 PHP 脚本返回匹配文档键的列表。然后,我使用该键列表将数据(使用 http_post_data)发布到列表函数(详细信息此处 ,在“查询选项”下)。此列表函数返回 HTML 格式的结果。这是有效的部分。
我的需求现在发生了变化,我只想查询视图并返回 JSON。但是,当我这样做时,这是 http_post_data 调用的响应:
HTTP/1.1 415 不支持的媒体类型 服务器:CouchDB/1.0.2(Erlang OTP/R13B) 日期:2011 年 7 月 9 日星期六 22:22:51 GMT 内容类型:text/plain;charset=utf-8 内容长度:78 缓存控制:必须重新验证 {“错误”:“bad_content_type”,“原因”:“内容类型必须是application/json”}
我为此视图生成的 URL 是正确的。我可以将 POST 调用更改为
http_post_data(url/of/view, $key_string, "Content-Type:application/json");
但实际上不会返回任何内容(我正在查看 Firebug 中的输出)。要发回我的结果,这里是相关的 PHP:
HttpResponse::setContentType("application/json"); HttpResponse::setData($response);
$response
包含对 CouchDB 的 http_post_data 调用的响应。
有什么建议吗?这已经让我发疯了一天多了。
谢谢。
First, here is what my current system looks like:
- CouchDB 1.0.2
- PHP 5.3.6
- Apache httpd 2.2.19
- PECL http 1.7.1
- CouchDB-Lucene 0.6.1
I am building a mini search engine with CouchDB and CouchDB-Lucene. When the user enters a query I POST to my PHP script which then queries couchdb-lucene. Couchdb-lucene will then return a list of matching document keys to the PHP script. Then, I POST data (with http_post_data) to a List Function with that list of keys (detailed here, under "Querying Options"). This List Function returns HTML formatted results. This is the part that works.
My needs are now changing and I would like to query only the view and get back JSON. However, when I do, this is the response from the http_post_data call:
HTTP/1.1 415 Unsupported Media Type
Server: CouchDB/1.0.2 (Erlang OTP/R13B)
Date: Sat, 09 Jul 2011 22:22:51 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 78
Cache-Control: must-revalidate
{"error":"bad_content_type","reason":"Content-Type must be application/json"}
The URL that I generate for this view is correct. I can change my POST call to
http_post_data(url/of/view, $key_string, "Content-Type:application/json");
but nothing will actually be returned (I am looking at output in Firebug). To send back my results, here is the relevant PHP:
HttpResponse::setContentType("application/json");
HttpResponse::setData($response);
$response
contains the response from the http_post_data call to CouchDB.
Any suggestions? This has been driving me mad for a day and a bit now.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http_post_data
应该接收选项的关联数组(而不是字符串)。您应该使用
array('headers' => array('content-type' => 'application/json'))
而不是"Content-Type:application/json"< /代码>
http_post_data
supposed to receive an assoc array (not a string) for options.You should use
array('headers' => array('content-type' => 'application/json'))
instead of"Content-Type:application/json"