A client called us up saying they had problems downloading files from our e-learning portal. After some back and forth on the phone I found out the problem was their browser and/or MIME types. Either the MIME type wasn't being set correctly or their browser was ignoring it. In any case the consequence was that the byte stream was being output to screen as garbled (Greek numbers, according to the client) text.
I wanted to check the HTTP headers the URL was returning, to make sure we were in fact setting the MIME type. Firebug shows the headers in the console and net tabs. In this case they weren't being displayed though, as the URL was initiating a download. Slightly stumped, I thought for a minute and remembered cURL.
I've never used cURL, but have read much of it. I guessed it could maybe do the trick, so I set about finding out. After a cursory search I found out that
$ curl -I -H http://URL
Would return the headers for the requested URL. The URL I was trying requires cookie-based authentication, though. After reading the manual I managed to log in via cURL, save the cookies in a text file, then request the file using the cookies to authenticate:
First I POSTed to the login form's
action URL with the necessary parameters, while saving the cookies generated by the POST to a text file. Then, using the text file I requested the file URL and, voilà, got what I needed.
$ curl -c cookies.txt -L -d "username=<USER>&pass=<PASS>" http://URL/login.php $ curl -c cookies.txt -b cookies.txt -L -I http://URL/file.pdf