GET returns HTTP/1.1 400 Bad Request

Please Help me

const char* ssid = "";
const char
password = "
******";

String values;

WiFiServer server(80);

const char* host = "http://dqq0.cafe24.com";
const int httpPort = 80;

void setup() {

Serial.begin(9600);
delay(10);

// Connect to WiFi network
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");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());
}

void loop() {

String str1(host);

WiFiClient client;
if (!client.connect(host, httpPort)) {
Serial.println("connection xxx");
return;
}

String url = "/bsapp2?equip=H001&value=24.70";
if(Serial.available()){
// We now create a URI for the request
Serial.print("Requesting URL: ");
String str = Serial.readStringUntil('\n');

client.println("Get /bsapp2?equip=H001&value=24.70");
client.println("Host: http://dqq0.cafe24.com");
client.println();


Serial.println("Get /bsapp2?equip=H001&value=24.70");
client.println("Host: http://dqq0.cafe24.com");

delay(1000);
Serial.println("Respond:");
while(client.available()){
  String line = client.readStringUntil('\r');
  Serial.print(line);
 }

}

Serial.println();
Serial.println("closing connection");

delay(5000);
}

SerialMonitor

Requesting URL: /bsapp2?equip=H001&value=24.70
Get /bsapp2?equip=H001&value=24.70 HTTP/1.1
Host: http://dqq0.cafe24.com
Respond:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Wed, 02 Aug 2023 02:33:42 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 150
Connection: close

CODE TAGS will get more friends and faster responses.

Why do you recreate the Client object every time through loop() ?

When I press Switch, then transmit requesting URL

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.