Curl receiving a 302 or something, weird

curl

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).

Best Answer

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