Why does curl crop this query string?

I am sure that the answer to this question will be a rather painfully obvious character encoding problem ...

I use curl on the command line to check for some endpoints in a python application. The endpoint accepts URL parameters for latitude and longitude. Nothing special. I entered the command:

curl -v -L http://localhost:5000/pulse/?lat=41.225&lon=-73.1 

The server responds with detailed curl output:

 * Connected to localhost (127.0.0.1) port 5000 (#0) > GET /pulse/?lat=41.225 HTTP/1.1 > User-Agent: curl/7.21.6 (i686-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3 > Host: localhost:5000 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 500 INTERNAL SERVER ERROR < Content-Type: application/json < Content-Length: 444 < Server: Werkzeug/0.8.1 Python/2.7.2+ < Date: Wed, 01 Feb 2012 17:06:29 GMT < { "msg": "TypeError: float() argument must be a string or a number", "flag": 0, "stack": [ "Traceback (most recent call last):", " File \"engine.py\", line 139, in dispatch_request", " return getattr(self, 'action_'+endpoint)(request, **values)", " File \"engine.py\", line 818, in action_getpulse", " lon = float(request.args.get('lon'))" ], "err": 1 * Closing connection #0 } [1]+ Done 

In the second line of this dump, it is obvious that the second lon parameter is not sent. What am I doing wrong? Thank.

+55
curl urlencode
Feb 01 '12 at 17:11
source share
2 answers

The answer to the question โ€œwhat am I doing wrongโ€ is that the shell sees the ampersand ( & ) and thinks the end of the command (and puts it in the background). You should quote this, so the answers that quote the line work. You could just as easily run this:

 curl -v -L "http://localhost:5000/pulse/?lat=41.225&lon=-73.1" 
+153
May 21 '12 at 19:10
source share

I think you can try the following:

  curl -v -L -d "lat=41.225&lon=-73.1" http://localhost:5000/pulse 

by default, it calls POST. If you want to send a GET request

  curl -v -L -G -d "lat=41.225&lon=-73.1" http://localhost:5000/pulse 



More details
and since you use localhost , if you should use https , you probably want to include -k as an option to ignore certificate errors

Thanks to Ross for pointing this out.

+29
Feb 01 2018-12-12T00:
source share



All Articles