logo elektroda
logo elektroda
X
logo elektroda

[Solved] Why can't I connect to the servers? An error appears: '400 Bad Request'.

dondu 603 3
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19334224
    dondu
    Moderator on vacation ...
    Hi,

    I need to make quick use of a Wemos ESP8266 NodeMCU v3 version Lolin module, bought about two years ago. I uniquely wanted to do this using the Arduino IDE. I used the example available in the IDE, Tried to connect to a few of my servers (still error), and below a sample to Onet.co.uk:


    Code: C / C++
    Log in, to see the code
    .

    The result is error 400:

    Quote:
    WiFi connected
    IP address:
    192.168.1.13
    connecting to onet.pl
    Requesting URL:
    GET HTTP/1.1
    Host: onet.pl
    Connection: close


    HTTP/1.1 400 Bad Request
    Server: Ring Publishing - Accelerator
    Date: Mon, 22 Mar 2021 10:00:10 GMT
    Content-Type: text/html
    Content-Length: 150
    Connection: close

    <html>
    <head><title>400 Bad Request</title></head>
    <body>
    <center><h1>400 Bad Request</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>



    I have also tried other examples, including for https for example:

    Code: C / C++
    Log in, to see the code


    Result:

    Quote:
    ......
    WiFi connected
    IP address:
    192.168.1.13
    connecting to onet.pl
    connection failed
    .

    Where to look for the cause?

    Added after 4 [hours] 2 [minutes]:

    Maybe it's about updating the firmware?
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 19335000
    Slawek K.
    Level 35  
    Try adding http:// or https:// before the hostname in the variable
    Code: C / C++
    Log in, to see the code
    in the call
    Code: C / C++
    Log in, to see the code
    .

    Greetings
  • ADVERTISEMENT
  • Helpful post
    #3 19335216
    ex-or
    Level 28  
    dondu wrote:
    // We now create a URI for the request
    String url = "";
    ....

    String uri = String("GET ") + url + " HTTP/1.1" +
    "Host: " + host + "■" +
    "Connection: close";
    .

    The error is caused by an empty string in the variable "url". The path to the requested resource needs to be inserted there, at a minimum: "/".
  • #4 19336258
    dondu
    Moderator on vacation ...
    ex-or wrote:
    The error is caused by an empty string in the "url" variable. You need to insert the path to the requested resource there, at a minimum: "/".
    .
    Thanks, that was the problem.
ADVERTISEMENT