Topic: HTTP GET Request results in 400 Bad Request

Dear all

I have problem with get request

#include <ESP8266WiFi.h>

const char* ssid = “EdimaxADSL”;
const char* password = “karim2017*”;
const char* host = “karimfouad.ezyro.com”;
const char* pin = “5555”;
const char* cost = “eee”;

void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED){

delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print(“Connecting to “);
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if(!client.connect(host, httpPort)){
Serial.println(” connected failed”);
return;
}
String url = “submitcust2.php”;
url += “?FirstName=”;
Serial.print("Request URL: ");
Serial.println(url);
client.print(String("GET “) + url + “HTTP/1.1\r\n” +
“Host: " + host + “\r\n” +
“Connection: close\r\n\r\n”);
unsigned long timeout = millis();
while (client.available() == 0){
if(millis() - timeout > 5000){
Serial.println(”>>>>> Client Timeout !”);
client.stop();
return;
}
}
while (client.available()){
String line = client.readStringUntil(’\r’);
Serial.print(line);
}
Serial.println();
Serial.println(“closing connection”);

}

Response

Connecting to karimfouad.ezyro.com
Request URL: submitcust2.php?FirstName=
HTTP/1.1 400 Bad Request
Server: nginx
Date: Wed, 31 May 2017 11:04:12 GMT
Content-Type: text/html
Content-Length: 166
Connection: close

400 Bad Request

400 Bad Request


nginx

Response

Connecting to karimfouad.ezyro.com
Request URL: submitcust2.php?FirstName=
HTTP/1.1 400 Bad Request

Well, don’t you think that not supplying a value after the = sign makes the request a bad request?

Thank you ! No, This not problem . iam put a value and get the same request.

No, This not problem . iam put a value

So, you are running some code other than what you posted, that you need help with. I can't help you with code I can't see.

Thank you , but this the same code and when you told me i tested it through put value and get the same problem.

but this the same code

If it IS the same code, it does NOT add a name after the = sign. If it adds a name after the = sign, it is NOT the same code.

Open a browser.

Point to http://karimfouad.ezyro.com/submitcust2.php?FirstName=NotTheSameCode.

What happens?

You need a slash before the page (url) and a space after it.

client.print(String("GET /") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "Connection: close\r\n\r\n");

SurferTim: You need a slash before the page (url) and a space after it.

client.print(String("GET /") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "Connection: close\r\n\r\n");

Thank you very much SurferTim work well, after your modification.

PaulS: If it IS the same code, it does NOT add a name after the = sign. If it adds a name after the = sign, it is NOT the same code.

Open a browser.

Point to http://karimfouad.ezyro.com/submitcust2.php?FirstName=NotTheSameCode.

What happens?

[", \n, \n, \n, \n, "]

every enter will increase \n, blank like this