Getting HTTP error code 400 with ESP-12

Hello!

I'm working on a small project for my ESP-12 but I'm having some issues. I'm getting HTTP error code 400 (invalid request) where the payload does not tell me whats wrong. The server I'm requesting just states something is wrong :frowning:

What I wish to to is to perform a GET request to a web server. At the moment I'm just polling my own web server to see if I could get a HTTP 200 (OK).

Im using the ESP8266HTTPClient.h library.

  http.begin("http://fagerbakke.net");
  http.addHeader("Content-Type", "text/html");
  http.addHeader("Accept", "text/html");
  http.addHeader("User-Agent", "ESP8266");

  int httpCode = http.GET()

  String payload = http.getString();

  Serial.print("HTTP code: ");
  Serial.println(httpCode);

As you guys can see I've tried to set different headers, I'm unsure on what standard the HTTP request is. My goal is to communicate with a API.

Could anyone point me in the right direction?

Im using the ESP8266HTTPClient.h library.

What did the example that came with the library look like? It seems strange that an object named http needs to be told to use the http protocol to talk to a server.

Okey, this is weird.

Sending a GET request to http://fagerbakke.net does not work. But a GET request to http://fagerbakke.net/ does! Spot the difference?

Spoiler: the added "/" seems to do the trick. I don't know why, any wizards that could explain? :smiley:

I'm not certain, but I'll take a guess. It is probably a two part thing.
The whole server/page = http://fagerbakke.net/
The server = http://fagerbakke.net
The page = /
as in
GET / HTTP/1.1
Without the slash, the GET would be malformed.
Just a guess.