ESP8266 AT Mode Connect Error returning 400 bad request by cloudflare

Problem Reproduction

This project is using ESP8266 to sending GET request to the custom URL by AT mode
but the response are not correct while doing the API requests.


  • Response
    1
    <html><head><title>400 Bad Request</title></head><body><center><h1>400 Bad Request</h1></center><hr><center>cloudflare</center></body></html>

Solution

  • After finding time on how to fix, I changed to other way to call the api and it started working after that
    1
    2
    3
    4
    esp8266_send_cmd("AT+CIPMODE=1", "OK", 100); // Enable transparent transmission
    esp8266_send_cmd("AT+CIPSEND", "OK", 100); // Start transparent transmission

    sprintf((char *)command, "GET /api/getuserstatus?username=%s HTTP/1.1\r\nHost: elec3300.marcoko.com\r\nConnection: close\r\n\r\n", username);
    And it works for no reasons

Also remember to turn off these Settings in Cloudflare if you don’t want to add more headers to ESP requests

  • Security -> Settings -> Browser Integrity Check : Off
  • Security -> Settings -> Security Level : Off
  • SSL/TLS -> Overview -> SSL/TLS encryption : Flexible / Off (Choose one)
  • DNS -> Records -> turn off the cloudflare proxies of the corresponding baseUrl