4

I have the following curl command

curl -X POST -w "\nRESULT CODE:%{http_code}\n" --insecure --header "Content-Type:application/json" --user robot-midc:1ZSXM7 -d @table.json http://databus.nrel.gov/api/registerV1

and I receive the following response

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.2.4</center>
</body>
</html>

hmmm, how do I check the actual http code, was it a 302 as curl docs claim they follow redirects so I am not sure what is going on?

thanks, Dean


hmmm, maybe this is a bug in that curl doesn't follow http to https redirect like browsers do???? My issue was simply that the load balancer always redirects to https and I had http on the line there....so odd, it would be nice for curl to give a better error in that it doesn't redirect to https (ie. doesn't follow all redirects like the documentation states).

Tom O'Connor
  • 27,480
  • 10
  • 73
  • 148
Dean Hiller
  • 911
  • 4
  • 15
  • 35

2 Answers2

8

Pass -L to cURL and it will follow the 302.

Michael-O
  • 261
  • 1
  • 2
  • 13
7

Add -v to curl to see the actual header responses.
And by default it doesn't follow redirects, add -L to also follow redirects, but (from the man page):

When authentication is used, curl only sends its credentials  to  the
initial  host.  If a redirect takes curl to a different host, it
won't be able to intercept the user+password. See  also  --location-trusted
on how to change this. 
faker
  • 17,496
  • 2
  • 60
  • 70