Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Post Request - ESP8266HTTPClient generates wrong http headers #2979

Closed
schlaubstar opened this issue Feb 18, 2017 · 2 comments
Closed

Comments

@schlaubstar
Copy link

Hi when using this simple code:

HTTPClient http;
string message="Hello from ESP8266";
http.begin("http://192.168.178.21:8000");
http.addHeader("Content-Type", "text/plain");
int httpCode = http.POST(message);
if(httpCode > 0) {
  Serial.printf("[HTTP] POST... code: %d\n", httpCode);
  if(httpCode == HTTP_CODE_OK) {
            String payload = http.getString();
            Serial.println(payload);
        }
    } else {
        Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }
http.end();

I always received the message: "error uploading payload" (like many others considering google and this issue list). So I did setup a server on my computer, to check about whats going on.

The matching message looks like this:
POST HTTP/1.1
Host: 192.168.178.34:8000
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
Content-Type: text/plain
Content-Length: 20

Hello from ESP8266!

The problem is caused by the wrong post header: If you manually generate the post message then it is working and everything looks the same except for the first line:
POST / HTTP/1.1

I assume, that HttpClient.Post(message) does generate a wrong header lacking one slash.
Maybe someone wants to fix this.

@igrr
Copy link
Member

igrr commented Feb 18, 2017

It looks like the URL you specify is lacking the trailing slash (after the port number). I suppose the library could be smart enough to handle this case and automatically add the slash, but it isn't :)

@schlaubstar
Copy link
Author

Damn ! You're a genious ! I'm so sorry > That issue can be closed. Obviously I just needed to add a trailing "/" to the host .... But maybe it is of help to others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants