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

Cannot call more than once ESP8266HttpClient POST() #1902

Closed
miky2k opened this issue Apr 12, 2016 · 2 comments
Closed

Cannot call more than once ESP8266HttpClient POST() #1902

miky2k opened this issue Apr 12, 2016 · 2 comments

Comments

@miky2k
Copy link

miky2k commented Apr 12, 2016

If i define ESP8266HttpClient websebd;
websend.begin("http://192.168.1.1/htpxml.php");
websend.addHeader("Content-Type", "text/xml");
websend.addHeader("Cookie:","XDEBUG_SESSION_START=session0");

then i call it two times:

websend.POST("some xml text");
websend.end();

websend.POST("another xml text");
websend.end();

POST /htpxml.php HTTP/1.1
Host: 192.168.1.1
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
Content-Type: text/xml
Cookie:: XDEBUG_SESSION_START=session0
Content-Length: 744
Content-Length: 744

(Wireshark log)

if(payload && size > 0) {
addHeader("Content-Length", String(size));
}

don't know if it's the right mode to use object, but i would like to avoid
recreate the same object every time i have to send same file to same
url with same header!!

The code in sendrequest that add "definitely" content size to header.
if(payload && size > 0) {
addHeader("Content-Length", String(size));
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@TheAustrian
Copy link

I don't know if it's cause you call the .end() but regarding setting up stuff only once I made myself a function that I then use in the loop().

int SendSensorData (String Sensordata) {
  // returns negative value if unsuccessful
  // returns 0 if successful (needs to be set up that way on the receiving webpage)
  String returnvalue = "-1";
  if (Sensordata != "" ) {
    HTTPClient http;
    http.begin(phppage);
    http.addHeader("Content-Type", contenttype);
    int httpCode = http.POST(Sensordata);
    if (httpCode != 200) {
      Serial.println("not successful");
      } else {
      returnvalue = http.getString();
      Serial.println("successful:" + returnvalue);   
      }
    http.end();
  } 
  int returnval = returnvalue.toInt();
  return returnval;
}

@miky2k
Copy link
Author

miky2k commented Apr 13, 2016

Apache does not agree with more than one Content-Length line in request,
i'dont know why your reuse work!!

@igrr igrr modified the milestones: 2.2.0, 2.3.0 Apr 18, 2016
igrr pushed a commit that referenced this issue Jun 6, 2016
* Add new boards Phoenix 1.0, Phoenix 2.0

* ESP8266HTTPClient: fix duplicate Content-Length headers (#1902)

* Add new boards Phoenix 1.0, Phoenix 2.0

* Add phoenix in variants.
@igrr igrr closed this as completed Jun 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants