title: Arduino Ethernet Shield:: HTTP/1.1 400 Bad Request
body: <p>I have the following Arduino code. It connects to a server and sends the sensor's readings to it. The reply from the server is always:</p>
  
  <blockquote>
    <p>HTTP/1.1 400 Bad Request</p>
  </blockquote>
  
  <p>The Arduino code is as follows.</p>
  
  <pre><code>#include &lt;Ethernet.h&gt;           //Library for Ethernet functions
  #include &lt;Client.h&gt;             //Library for client functions
  #include &lt;OneWire.h&gt;            //Library for the onewire bus
  #include &lt;SPI.h&gt;
  
  // Ethernet settings
  uint8_t hwaddr[6]   = {0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xBE}; // MAC address of Arduino
  uint8_t ipaddr[4]   = {192, 168,   0, 55};                  // IP address of Arduino
  uint8_t gwaddr[4]   = {192, 168,   0,  1};                  // IP address of gateway ( for later DNS implementation)
  uint8_t subnet[4]   = {255, 255, 255,  0};                  // Subnet mask           ( for later DNS implementation)
  uint8_t serverip[4] = {192, 168,   0, 54};                  // IP address of server arduino sends data to
  
  uint8_t serverport = 80;                                    // The port the Arduino talks to
  
  EthernetClient client;           // Make a new instance from type "Client" named "client", giving it
  int numSensors;                  // a variable to store the number of sensors.
  
  bool connected = false;          // Yes-no variable (boolean) to store if the arduino is connected to the server.
  int i = 0;                       // Variable to count the sendings to the server.
  
  void setup() {
      Serial.begin(9600);                                       // Start the serial port
      Serial.println("Initializing Ethernet.");
      Ethernet. begin(hwaddr, ipaddr);                          // Start up Ethernet
  }
  
  void loop() {
      if(!connected)   {                                        // If "not" connected print: not connected ;)
          Serial.println("Not connected");
          Serial.println("Connecting to server...");
          if (client.connect(serverip, serverport)) {           // If connected, set variable connected to "true" and
              connected = true;
              Serial.println("connected!!");
              String data;
              data+="";
              data+="t0=";
              data+=analogRead(A0);
              //    data+="&amp;&amp;";
              //    data+="t1=";
              //    data+=analogRead(A1);
              //    data+="&amp;&amp;";
              //    data+="t2=";
              //    data+=analogRead(A2);
              Serial.println("Sending to Server: ");
              Serial.println();
              client.print("GET /formSubmit.php?" + data);
              Serial.print("GET /formSubmit.php?" + data);
              client.println(" HTTP/1.1");
              Serial.println(" HTTP/1.1");
              client.println("Host: http://localhost/PhpProject1");
              Serial.println("Host: http://localhost/PhpProject1");
              client.println("User-Agent: Arduino");
              Serial.println("User-Agent: Arduino");
              client.print("Content-Length: ");
              Serial.print("Content-Length: ");
              client.println(data.length());
              Serial.println(data.length());
              client.println("Accept: text/html");
              Serial.println("Accept: text/html");
              client.println("Connection: close");
              Serial.println("Connection: close");
  
              client.println();
              Serial.println();
  
              if (client.available()) {
                  char c = client.read();
                  Serial.print(c);
              }
              delay(10000);
          }
          else {
              Serial.println("Cannot connect to Server");       //  else block if the server connection fails (debugging)
          }                                                     
      }                                                         
      else {                                                    
          delay(500);                                           //
          while (client.connected() &amp;&amp; client.available()) {    // When connected and availabe:
              char c = client.read();                           // read the answer of the server and
              Serial.print(c);                                  // print it to serial port
          }
          //
          Serial.println();                                     //
          client.stop();                                        // Stop the connection and set
          connected = false;                                    // "connected" to false
      }
  }
  </code></pre>
  
  <p>The output on the serial monitor after uploading this code is:</p>
  
  <pre><code>Initializing Ethernet.
  Not connected
  
  Connecting to server...
  connected!!
  
  Sending to Server:
  
  GET /formSubmit.php?t0=433 HTTP/1.0
  Host: http://localhost/PhpProject1
  User-Agent: Arduino
  Content-Length: 6
  Accept: text/html
  Connection: close
  
  
  
  HTTP/1.1 400 Bad Request
  Date: Sat, 03 Nov 2012 17:06:00 GMT
  Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
  Content-Length: 343
  Connection: close
  Content-Type: text/html; charset=iso-8859-1
  
  &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;400 Bad Request&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Bad Request&lt;/h1&gt;
  &lt;p&gt;Your browser sent a request that this server could not understand.&lt;br /&gt;
  &lt;/p&gt;
  &lt;hr&gt;
  &lt;address&gt;Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 Server at http://localhost/PhpProject1 Port 80&lt;/address&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>What might be the problem?</p>