Ethernet Shield to UPC site

Hi there,

I'm testing the dnswebclient example that come with Arduino IDE.
Version 23
Ethernet Shield - Sparkfun, just received it.
Arduino Uno

Using the example dnswebclient sketch, I'm trying to connect to a upc site and retrieve product information using the barcode. In this case it is a rice mix.
I receive a "404 not Found " error.
Works fine if I use the string in a browser, returns the info.

I have not be able to find any topics on this and wondering if anyone has seen this issue?

The code and return data is included below. I did not change the example except for the URL.
Tested with the google example and it worked fine.

Thanks
Randy

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 API Key - c4f9ccc27f967b1cc0ba3c5fde92f3a8
www.upcdatabase.org/api/xml/c4f9ccc27f967b1cc0ba3c5fde92f3a8/UPCGoesHere

OUTPUT if Exists
<?xml version="1.0" encoding="ISO-8859-1"?>
 <output xmlns="http://www.upcdatabase.org/">
     <valid>true</valid>
     <number>0111222333444</number>
     <itemname>UPC Database Testing Code</itemname>
     <description>http://www.upcdatabase.org/code/0111222333444</description>
     <price>123.45</price>
     <ratingsup>2</ratingsup>
     <ratingsdown>0</ratingsdown>
 </output> 
 
 OUTPUT if ERROR
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <output xmlns="http://www.upcdatabase.org/">
 <valid>false</valid>
 <error>301</error>
 <reason>Code does not exist!</reason>
 </output> 

Error codes:
 
 101 - API Key length is incorrect
 105 - API Key incorrect
 201 - You did not enter a code
 205 - The code you entered was non-numeric
 301 - Code does not exist

 created 18 Dec 2009
 by David A. Mellis
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(174,122,37,98); // www.upcdatabase.org
String Testupc = "071429097056";
char serverName[] = "www.upcdatabase.org";
// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /api/xml/c4f9ccc27f967b1cc0ba3c5fde92f3a8/071429097056 HTTP/1.0"); //HTTP/1.0
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

Message returns

connected
HTTP/1.1 404 Not Found
Date: Sat, 17 Dec 2011 03:08:03 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_fcgid/2.3.6 Phusion_Passenger/3.0.9 mod_bwlimited/1.4
Accept-Ranges: bytes
Connection: close
Content-Type: text/html
X-Pad: avoid browser bug



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>404 Not Found</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        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;
        }
    </style>
  </head>
  <body>
    <div id="body-content">  
<!-- start content-->

<!-- 
 instead of REQUEST_URI, we could show absolute URL via:
 http://HTTP_HOST/REQUEST_URI
    but what if its https:// or other protocol?
    
    SERVER_PORT_SECURE doesn't seem to be used
    SERVER_PORT logic would break if they use alternate ports
-->

<h1>404 Not Found</h1>
<p>The server can not find the requested page:</p>
  <blockquote>
    (none)/api/xml/c4f9ccc27f967b1cc0ba3c5fde92f3a8/071429097056 (port 80)
  </blockquote> 
<p>
    Please forward this error screen to zemni.site5.com's 
    <a href="mailto:system-notifications@monitor.accountsupportgroup.com?subject=Error message [404] 404 Not Found for (none)/api/xml/c4f9ccc27f967b1cc0ba3c5fde92f3a8/071429097056 port 80 on Friday, 16-Dec-2011 21:08:03 CST">
    WebMaster</a>.
</p>
<hr />
<address>Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_fcgid/2.3.6 Phusion_Passenger/3.0.9 mod_bwlimited/1.4 Server at zemni.site5.com Port 80</address>


<!-- end content -->
    </div>
  </body>
</html>

disconnecting.

Can you use a network sniffer (running on a PC) to analyze what is sent over the wire?

Christoph

The server is using virtual hosting. You must send a "Host: www.upcdatabase.org" in the header after the GET.

Add: I was rudely interrupted by this thing called "work". Imagine that!!

    client.println("GET /api/xml/c4f9ccc27f967b1cc0ba3c5fde92f3a8/071429097056 HTTP/1.0"); //HTTP/1.0
    client.println("Host: www.upcdatabase.org");
    client.println();

I think HTTP/1.0 supports the Host header. I haven't tested that. It may require HTTP/1.1

Thanks for the reply cwienands but SurferTim is right on the money.
The HTTP post was ok and returned the correct data.

I just added the host line as SurferTim suggested and it work perfectly.

Thanks SurferTim...you the man!