HTTP request fails with DnsWebClient

I am using this code to make an HTTP request to my webserver

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x01, 0x25 };
char serverName[] = "www.inteliouse.com";
EthernetClient client;

void setup() {
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    while(true);
  }
  delay(1000);
  Serial.println("connecting...");
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    client.println("GET /service.php 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();
    while(true);
  }
}

and I get the following response

connecting…
connected
HTTP/1.1 400 Bad Request
Date: Fri, 10 Feb 2012 22:34:05 GMT
Server: Apache
Content-Length: 277
Connection: close
Content-Type: text/html; charset=iso-8859-1

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.


Apache Server at * Port 80

disconnecting.

while if I made the request to google.com it returns a valid response knowing that the requested page exists and have a body
can somebody help me with this ?

HTTP/1.1 400 Bad Request

Does your server understand HTTP 1.1? Perhaps you need to use 1.0.

actually the same with HTTP1.0
I used HTTP version 1.0 and I am getting the following response

connecting…
connected
HTTP/1.1 404 Not Found
Date: Fri, 10 Feb 2012 22:55:22 GMT
Server: Apache
Accept-Ranges: bytes
Connection: close
Content-Type: text/html

404 Not Found body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-color:#367E8E; scrollbar-base-color: #005B70; scrollbar-arrow-color: #F3960B; scrollbar-DarkShadow-Color: #000000; color: #FFFFFF; margin:0; } a { color:#021f25; text-decoration:none} h1 { font-size: 18px; color: #FB9802; padding-bottom: 10px; background-image: url(sys_cpanel/images/bottombody.jpg); background-repeat: repeat-x; padding:5px 0 10px 15px; margin:0; } #body-content p { padding-left: 25px; padding-right: 25px; line-height: 18px; padding-top: 5px; padding-bottom: 5px; } h2 { font-size: 14px; font-weight: bold; color: #FF9900; padding-left: 15px; }

404 Not Found

The server can not find the requested page:

(none)/service.php (port 80)

Please forward this error screen to *'s WebMaster.


Apache Server at * Port 80

disconnecting.

You might want to read up on HTTP a bit more...

What if you add the line "Host: www.inteliouse.com" after your GET line?

Think about it this way...you just connected to an IP address. Now you're requesting /service.php. From what site? A lot of times you can have multiple sites hosted on the same server, so you need to tell it what site is being accessed.

Hopefully that's the problem.

And you don't really need to paste the entire HTML error response...just the headers have everything relevant.

actually the same with HTTP1.0

In one case, you got a 400 error code (badly formed request). In the other case, you got a 404 error code (file not found). I hardly think that these are the same.

I would suggest you check the "/service.php" part of the below to ensure correct spelling, capitalization, directory location and such. I tried the DnsWebClient code with my web server and it worked without issues.

client.println("GET /service.php HTTP/1.1");

actually you are right @macegr many websites on the same host , and all I get is the ip address of the host In my case I used the username to denote my pages

char serverName[] = "www.inteliouse.com";
client.println("GET /~myusername/service.php HTTP/1.0");

and this is the response that I got

connecting...
connected
HTTP/1.1 200 OK
Date: Sat, 11 Feb 2012 11:40:44 GMT
Server: Apache
Connection: close
Content-Type: text/html

thank you

macegr: You might want to read up on HTTP a bit more...

What if you add the line "Host: www.inteliouse.com" after your GET line?

Think about it this way...you just connected to an IP address. Now you're requesting /service.php. From what site? A lot of times you can have multiple sites hosted on the same server, so you need to tell it what site is being accessed.

Hopefully that's the problem.

This recommendation helped a lot. Thank you!

Here's exactly how mine looked when it ran successfully:

   client.println("GET /some-webpage.html HTTP/1.0"); 
   client.println("host:example.com");