Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:39:14+00:00 2026-06-13T20:39:14+00:00

I have the following Arduino code. It connects to a server and sends the

  • 0

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:

HTTP/1.1 400 Bad Request

The Arduino code is as follows.

#include <Ethernet.h>           //Library for Ethernet functions
#include <Client.h>             //Library for client functions
#include <OneWire.h>            //Library for the onewire bus
#include <SPI.h>

// 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+="&&";
            //    data+="t1=";
            //    data+=analogRead(A1);
            //    data+="&&";
            //    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() && 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
    }
}

The output on the serial monitor after uploading this code is:

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

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 Server at http://localhost/PhpProject1 Port 80</address>
</body></html>

What might be the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:39:19+00:00Added an answer on June 13, 2026 at 8:39 pm

    You request is bad.

    1. Host field must not contain /, try: Host: localhost
    2. Content-Length make no sense in GET method
    3. Maybe you need to terminate each lines by \r\n instead of just \n (depending on server)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fetching data from the following database: I have arduino-box that send that
I have a constructor for my Arduino-code which is something like the following: class
I have following code.. $query = SELECT quote, author FROM quotes ORDER BY id
I have the following code on my Arduino that constantly checks for a serial
I have following code var res = from c in model.Data select new object[]
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I have the following char inside an Arduino sketch: char inData[80]; When I print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.