JAndrassy / WiFiEspAT

Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.
GNU Lesser General Public License v2.1
288 stars 44 forks source link

HTTP 400 Bad Request when ussing https #25

Closed iactiva closed 3 years ago

iactiva commented 3 years ago

Hello, I'm using this library for posting some data to a url however I'm getting HTTP400 when using ssl port 443 but it is working correctly if using non-secure port 80. Web server is nginx using Let's Encrypt SSL certificate and tested it to work on TSL 1.2 My module is a ESP01 just updated to JB AT 1.7 firmware

I've tried both WiFiSSLClient client > client.connect(hostname, 443) and WiFiClient client > client.connectSSL(hostname, 443)

I'm currently posting data to the same server using WiFiNINA library in some other modules w/o issues. Any suggestion on how to find out a solution? Thank you!

JAndrassy commented 3 years ago

HTTP 400 is "Bad request". it is a response from the server so connect() was successful. 400 is usually an error with HTTP protocol, not with transport.

iactiva commented 3 years ago

Thank you for your reply jandrassy. I've noticed something weird. Testing your samples with different hosts WiFiSSLClient works for Hostname api.github.com GET /repos/jandrassy/WiFiEspAT/commits/master/status However it returns HTTP 400 for Hostname arduino.cc GET /asciilogo.txt (https://www.arduino.cc/asciilogo.txt)

JAndrassy commented 3 years ago

arduino.cc has the updated TLS, which doesn't work with AT firmware only with Jiri Bilek's special firmware. did you connect to arduino.cc or to www.arduino.cc?

iactiva commented 3 years ago

I have all modules flashed with with Jiri Bilek's latest firmware v.0.2.3 Connecting to arduino.cc returns HTTP 400 however www.arduino.cc works!

I'm playing now with AT commands and noticed this works properly:

AT+CIPMUX=0 AT+CIPSTART="SSL","arduino.cc",443 AT+CIPSEND=49 GET /asciilogo.txt HTTP/1.1 Host: arduino.cc

JAndrassy commented 3 years ago

show me the sketch which has 400 for arduino.cc

iactiva commented 3 years ago

Sure. This is the provided WiFiSSLClient.ino sample just replacing hostname and GET path.

`#include

const char* server = "arduino.cc";

WiFiSSLClient client;

void setup() { Serial.begin(115200); while (!Serial);

Serial1.begin(115200); WiFi.init(Serial1);

if (WiFi.status() == WL_NO_MODULE) { Serial.println(); Serial.println("Communication with WiFi module failed!"); // don't continue while (true); }

// waiting for connection to Wifi network set with the SetupWiFiConnection sketch Serial.println("Waiting for connection to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print('.'); } Serial.println(); Serial.println("Connected to WiFi network.");

Serial.println("Starting connection to server..."); if (client.connect(server, 443)) { // port 443 is the default https port Serial.println("connected to server");

client.println("GET /asciilogo.txt HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("User-Agent: Arduino");
client.println("Connection: close");
client.println();
client.flush();

} }

void loop() {

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

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

// do nothing forevermore
while (true);

} }`

Here is the output HTTP 400: `Waiting for connection to WiFi . Connected to WiFi network. Starting connection to server... connected to server

400 Bad Request

400 Bad Request


nginx

disconnecting from server.`

JAndrassy commented 3 years ago

could you turn on logging? https://github.com/jandrassy/WiFiEspAT#logging

iactiva commented 3 years ago

Hi @jandrassy, Sorry for the big delay in answering. It took me some time to stock some new ESP-01 modules. There seems this issue was something telated to those old modules as these new ones seem to be working as expected... so I'm closing this issue. Many thanks for your support.