I am trying to GET a page from my localhost server using the command line on linux.
I have my node’s REST endpoint like this:
app.get('/autogen',function(req, res) { res.set('Content-Type', 'text/plain'); res.status(200).send("OK"); });
And going here on my browser works perfectly:
However, I can’t figure out how to use CURL to do the same GET request via the command line.
Here is what I have tried:
curl -H "Accept: */*" -X GET http://localhost:8084/autogen -v
curl --ipv4 -H "Accept: */*" -X GET http://localhost:8084/autogen -v
curl -i -H "Accept: */*" -X GET http://localhost:8084/autogen -v
curl -H "Accept: text/html" -H "Content-Type: text/html" -X GET http://localhost:8084/autogen -v
curl -H "Accept: text/html" -X GET http://localhost:8084/autogen -v
curl -H "Accept: text/plain" -H "Content-Type: text/plain" -X GET http://localhost:8084/autogen -v
curl -I -H "Accept: */*" -X GET http://localhost:8084/autogen -v
curl --ipv4 -X GET http://localhost:8084/autogen -v
ALL CURL COMMANDS RETURN Response: HTTP/1.1 204 No Content
==================================
Logs & Info
Here is the full log of the response message from the CURL commands above (substituted sections with {}):
* About to connect() to proxy {MYCOMPANYPROXY} port 8080 (#0) * Trying {MYIP}... connected * Proxy auth using Basic with user '{MYNAME}' > GET http://localhost:8084/autogen HTTP/1.1 > Proxy-Authorization: Basic {...} > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: localhost:8084 > Proxy-Connection: Keep-Alive > Accept: text/plain > Content-Type: text/plain > < HTTP/1.1 204 No Content < Cache-Control: no-cache < Pragma: no-cache < Content-Type: text/html; charset=utf-8 < Proxy-Connection: Keep-Alive < Connection: Keep-Alive < Content-Length: 21958 < * Excess found in a non pipelined read: excess = 3013 url = /autogen (zero-length body) * Connection #0 to host {MYCOMPANYPROXY} left intact * Closing connection #0
Also here is the full headers from vising the page via chrome:
Also my no_proxy environment variable is set to not be used on localhost:
echo $no_proxy localhost,127.0.0.1,*.dom1,*.grp
And here’s the versions of what I’m using:
**Express Version: 3.14.0 **Node Version: v6.5.0 **Curl version: curl 7.22.0 (x86_64-pc-linux-gnu)
Also, side note, my server will tell me when someone goes to that page like
GET /autogen 200 10.168 ms - 2 GET /autogen 304 1.617 ms - -
But when I use the curl commands I get NOTHING so it must not be resolving or something
Advertisement
Answer
@dave_thompson_085 helped me with this one!
Apparently chrome was not using a proxy, and curl was, and I do NOT want to use the proxy.
The cause was my curl settings file ~/.curlrc
. It contained something like this:
proxy=http://myuser:mypass@myproxy
So, I removed ~/.curlrc
and BAM! Works now!
Thank you!