开发者

CouchDB 1.0.2 http_post_data on View from PHP Pecl Error Bad Content Type

First, here is what my current system looks like:

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.


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"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜