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:
- CouchDB 1.0.2
- PHP 5.3.6
- Apach开发者_如何学运维e 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.
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"
精彩评论