Hi Kai,
On May 18, 2009, at 2:40 PM, Kai Griffin wrote:
Hi Brian,
Thanks for your help.
I've been escaping the square brackets and double quotes in curl,
like this \[\" ....\" \] - which seems to work. I'll start using -
g in curl so I don't have to escape the square braces.
Wrapping the url in single quotes results in the single quote being
interpreted as part of the url itself, and curl complains that
"protocol 'http is not supported".
As for %22's... I cannot make that work at all. If I encode double
quotes as %22's in curl, couchdb complains about invalid JSON, and
it looks as if all the %'s have been stripped out and the 22's
become part of the request. For example the following request:
curl -g -X GET http: (...url...)?startkey=[%22SYD%22,%22LAX
%22,%222008-01-01T00:00:00Z%22%]&endkey=[%22SYD%22,%22LAX
%22,%222008-01-05T23:59:59Z
%22]&group=true&stale=ok
....results in the following error from couchdb:
{"error":"invalid_json","reason":"[22,22,-01-01T00:00:00Z]"}
You are on windows, right? In the regular windows shell, environment
variable substitution is done with %ENV_VAR_NAME% (roughly equivalent
to $ENV_VAR_NAME in bash). So %22SYD%22 would mean "take the value of
the 22SYD environment variable and concatenate 22". If there is no
such env var, the result would just be "22". This fits with the
invalid JSON couchdb is seeing.
Long story short, I think you need to escape the '%'s from the windows
shell. I don't know how to do this, but I'm sure it is possible.
Rhett
Replacing all the %22's with escaped double quotes (like this:
\" ) works perfectly; I get the rows I was expecting.
Somewhere along the line, those %'s are being stripped out and the
request mangled. I will fire up my linux laptop later and see if
any of these problems exist there.
Cheers,
Kai
On 18/05/2009 13:46, Brian Candler wrote:
On Sun, May 17, 2009 at 10:17:59AM +0200, Kai Griffin - Relaxing
wrote:
The trouble is, couchdb fails to return any rows when those quotes
are encoded as %22's like that.
Are you sure? Can you tun the same curl command line twice, once
where it
works, and once which is identical except you replace every double
quote
with %22 ?
Note 1: make sure the whole URL goes inside single quotes:
curl 'http://127.0.0.1:5984/.....'
Note 2: be careful with square brackets and curl, as it will try to
perform
its own globbing on them. Either use the -g flag to curl, or encode
your
square brackets as %5B and %5D.
HTH,
Brian.