cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: corect use of curl

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 25 Mar 2011 13:17:12 +0100 (CET)

On Fri, 25 Mar 2011, John Norris wrote:

> I am using curl for testing a rest service.

> curl -X PUT -u xxxxx:xxxxxx -H "Content-Type: application/json" -d
> '{"param1" : "TS-1", "param2" : "10003"}'
> http://localhost:9999/a/b/c/link/TS-3

> curl: (6) Could not resolve host: :; Host not found
> curl: (6) Could not resolve host: TS-1,; Host not found
> curl: (6) Could not resolve host: param2; Host not found
> curl: (6) Could not resolve host: :; Host not found

Are you possibly using Windows? That so looks like a completely broken shell
that doesn't properly deal with single-quotes vs double-quotes.

I just tried that command line and it worked fine on my linux box.

> Now I have successfully used curl like this
> curl -X PUT -u xxxxx:xxxxx
> "http://localhost:9999/a/b/c/link/TS-3?param1=TS-1&param2=10003"
>
> A few questions. Does curl translate the first format into the second format
> (possibly not or it would work))

No. curl is a pretty detailed and versatile tool and it does what you ask it
to do as much as possible. It also allows you to send completely weird things
if that is what you tell it to do.

If you ask it to send data in the request-body (like with -d) then it will do
so. If you ask it to send lots of stuff in the request-uri part of the HTTP
request and you stuff data in the query part like in your second example, then
curl will do that.

> Also, looking at the logs, despite the host not found statements, it does
> get through to my code but 10003 is not seen as a number but then it may be
> taking another value as param2.

You get the "Host not found" errors because your shell doesn't make the full
string after -d as a single argument, but instead it passes it on as many and
curl will treat all those arguments as individual URLs (and curl is friendly
enough to accept URLs without a starting protocol:// sequence) and thus it
will try to resolve those as host names...

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-03-25