Jump to content

Recommended Posts

Posted

<div class="KonaBody"><p><img src="http://osxdaily.com/wp-content/uploads/2011/07/get-http-header-from-website-with-curl.jpg" alt="Retrieve HTTP Headers with curl" title="get-http-header-from-website-with-curl" width="569" height="220" class="aligncenter size-full wp-image-18419" /></p>

<p>The easiest way to get HTTP header information from any website is by using the <a href="http://osxdaily.com/category/command-line/">command line</a> tool curl. The syntax goes like this:</p>

<p><code>curl -i url</code></p>

<p>Try it out yourself, here’s an example using Google.com:</p>

<p><code>curl -i www.google.com</code></p>

<p>You’ll see a ton of minified HTML, just scroll up in the terminal window to the lines directly succeeding the curl command to find the HTTP header information, which might look something like this:

<span id="more-18406"></span></p>

<blockquote><p>HTTP/1.1 200 OK

Date: Thu, 07 Jul 2011 22:15:57 GMT

Expires: -1

Cache-Control: private, max-age=0

Content-Type: text/html; charset=ISO-8859-1

Set-Cookie: PREF=ID=741dreb25486514f:FF=0:TM=13154488957:LM=15526957:S=kmFi3jKGDujg; expires=Sat, 06-Jul-2013 22:15:57 GMT; path=/; domain=.google.com

Set-Cookie: NID=48=8jFij8f8Lej115z89237iaa8sdoA8akjak8DybmLHXMC6aNGyxM8DnyNv-

iYjF09QhiCq2MdM3PKJDSFlkJalkaPHAU4JQy7MM8MKDQKEFLPqzoTSBPLKJLKMmdILlkdjel; expires=Fri, 06-Jan-2012 22:15:57 GMT; path=/; domain=.google.com; HttpOnly

Server: gws

X-XSS-Protection: 1; mode=block

Transfer-Encoding: chunked

</p></blockquote>

<p>An easy way to get around all the HTML, Javascript, and CSS nonsense is to use the -D flag to download the header itself into a separate file, and then open that file in your preferred text editor:</p>

<p><code>curl -iD httpheader.txt www.apple.com && open httpheader.txt</code></p>

<p>This is the same curl command as before with a few modifiers. The use of the double ampersand tells the command to only open the file if the header was successfully downloaded. Using ‘<a href="http://osxdaily.com/2007/02/01/how-to-launch-gui-applications-from-the-terminal/">open</a>‘ will open httpheader.txt in the default GUI text editor, which is generally Text Edit, but you could use vi, nano, or any of your preferred command line tools:</p>

<p><code>curl -iD httpheader.txt www.apple.com && vi httpheader.txt</code></p>

<p>curl is a powerful utility that is worth familiarizing yourself with. Anyone involved with the web should get some good use out of the header trick, and web developers can also <a href="http://osxdaily.com/2011/04/09/quickly-grab-and-copy-html-css-source-with-curl/">use curl to copy all the HTML and CSS</a> from a website very quickly.</p>

</div>

<p><a href="http://feedads.g.doubleclick.net/~a/4m9mCHL-NV3M7_XR3ociQzvwu_E/0/da"><img src="http://feedads.g.doubleclick.net/~a/4m9mCHL-NV3M7_XR3ociQzvwu_E/0/di" border="0" ismap="true"></img></a><br/>

<a href="http://feedads.g.doubleclick.net/~a/4m9mCHL-NV3M7_XR3ociQzvwu_E/1/da"><img src="http://feedads.g.doubleclick.net/~a/4m9mCHL-NV3M7_XR3ociQzvwu_E/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">

<a href="http://feeds.feedburner.com/~ff/osxdaily?a=DPIZ9X90ZXk:pC2YqhnBAOk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=DPIZ9X90ZXk:pC2YqhnBAOk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=DPIZ9X90ZXk:pC2YqhnBAOk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=DPIZ9X90ZXk:pC2YqhnBAOk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=DPIZ9X90ZXk:pC2YqhnBAOk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=DPIZ9X90ZXk:pC2YqhnBAOk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=DPIZ9X90ZXk:pC2YqhnBAOk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a>

</div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/DPIZ9X90ZXk" height="1" width="1"/>

 

View the full article

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days


×
×
  • Create New...