-1

I installed cURL in Windows using the following website: https://curl.haxx.se. I executed the following command on Command Line in Windows 64 bit:

    curl www.google.com

The result returned on executing the above command is:

    <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/?gfe_rd=cr&amp;ei=5cadWYGnDY-
    DoAOehquQDg">here</A>.
    </BODY></HTML>

I expected a result in XML/JSON format instead of HTML. I am not sure why I am getting this. I have tried using a cURL command with a server as well, and specified XML there for the result format. In that case also, HTML code is being returned. Is there any way to resolve this issue?

Any help is appreciated. Thanks in advance.

Unknown94
  • 47
  • 6
  • 1
    Why did you expect a result in XML/JSON format? You requested the home page of Google, which is an HTML page. – IMSoP Aug 23 '17 at 18:34
  • Why does the HTML code state 'The document has moved' in it? If the homepage HTML code is being returned, then this should not be there right? – Unknown94 Aug 23 '17 at 18:39
  • 1
    @Unknown94: It says "The document has moved" because www.google.com is performing a 302 redirect to www.google.co.in (likely based on your IP address). – jwodder Aug 23 '17 at 19:17
  • 1
    And if you fetch www.google.co.in instead, you'll get the same frightening amount of compressed inline JS that you get when clicking "View Source" in a browser. I'm not sure what JSON or XML you're expecting to see in its place. – IMSoP Aug 23 '17 at 21:26

1 Answers1

0

302 status code means document was moved from it's original location.

In order for curl to follow redirects you need to pass -L as suggested here.

curl -L www.google.com
orhtej2
  • 2,133
  • 3
  • 16
  • 26