Amit
Amit

Reputation: 7035

curl www.google.com works differently when the url is called from browser directly

When I type curl www.google.com in the terminal I get the below reply. But when I type the similar url(www.google.com) in browser(chrome) I get redirected to www.google.co.in

Why am I not able to see the below HTML when I call the same URL from browser?

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.in/">here</A>.
</BODY></HTML>

Upvotes: 10

Views: 68587

Answers (2)

Sergey Eremin
Sergey Eremin

Reputation: 11080

curl -L http://www.google.com

Will make curl follow redirects and you will recieve actual search page.

Upvotes: 24

Marc B
Marc B

Reputation: 360702

Browsers automatically follow redirects, so that intermediate page will only be available for a microscopic fraction of time before the .co.in version of the page is loaded. CURL, by default, does NOT follow redirects, so you get that intermediate page instead.

Upvotes: 6

Related Questions