Program error

The following code gives error in college LAN with Internet availability:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 12, 32 };
byte server[] = { 64, 233, 187, 99}; // Google

EthernetClient client;

void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);

delay(1000);

Serial.println("connecting...");

if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.1");
client.println();
} else {
Serial.println("connection failed");
}
}

void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;:wink:
;
}
}

The error is as follows:

connecting...
connected
HTTP/1.1 302 Found
Location: arduino - Google Search
Cache-Control: private
Content-Type: text/html; charset=UTF-8
P3P: CP="This is not a P3P policy! See P3P and Google's cookies - Google Account Help for more info."
Date: Tue, 22 Dec 2015 07:48:39 GMT
Server: gws
Content-Length: 281
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=74=rYq-dcxYVf88IB0Xl-dv1oxFV7NFgvEYZHkny4gpzj3HVJzFtP6-W6R_MmNn_dzmRWHAlRZTOmKnNz0OqyloL9N7eKzp_p2jgKES0AEqVrmlxyEK2oClDZE-9hisLX6lBwicic69; expires=Wed, 22-Jun-2016 07:48:39 GMT; path=/; domain=.google.com; HttpOnly

302 Moved

302 Moved

The document has moved here.

disconnecting.

What is the error ?

The sketch connects to a server of Google, that works.
The sketch reads the reply, that works.

The reply means that google want to reload a new page for the local language. That's not an error.

Shouldn't it say 200 ok? If I use any other server instead of Google it gives Bad Request.

Shouldn't it say 200 ok?

No.

If I use any other server instead of Google it gives Bad Request.

Post THAT code and the output.

You use this example ? Ethernet - Arduino Reference

If you do "/search?q=arduino HTTP/1.1" with any other server, that will not be recognized.

Could you try to ping "www.google.co.in" to find that IP address ? If I do that from Europe, I get mixed results.

Instead of using the IP for 'server', I think you can do a string as well.
Could you try this:

// byte server[] = {  64, 233, 187, 99}; // Google
byte server[] = "www.google.co.in"; // Google

I don't have my Ethernet Shield near me, so I can't test it.

Everything is working fine. You connect to the sever, and the sever gives you a 302 redirect. This means that you need to look at the "Location" header in the reply,

Location: arduino - Google Search

And go fetch that.

In answer to the obvious question "Why", the answer is: "that's the way that the website you have connected to works". Its a common pattern. The initial URL performs the search and stores the results of the search in a temporary bucket that you can page through. The second url is page 1 of the bucket. The bucket will remain in existence for a period of time - a few minites. If you go there after that period of time, you get a message "Your search results have expired".

See https://www.ietf.org/rfc/rfc2616.txt for more info.

-- EDIT --

If you want a machine to talk to google, then it would be better off using the JSON interface. You'll grt back the results of the search without all the HTML razamatazz.

See