Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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

share|improve this answer
add comment

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. 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.