Skip to content

Add .sendBody() #22

@tigoe

Description

@tigoe

With mult-line POST requests, there is currently no way to send a body except using a sendHeader() call. A sendBody() would be useful in this regard.

The following code works, but is confusing to the end user:

HttpClient http(netSocket, wemo.c_str(), port); // make an HTTP client
  http.connectionKeepAlive();             // keep the connection alive
  http.beginRequest();                    // start assembling the request
  http.post(route);                       // set the route
  // add the headers:
  http.sendHeader("Content-type", "text/xml; charset=utf-8");
  String soapAction = "\"urn:Belkin:service:basicevent:1#SetBinaryState\"";
  http.sendHeader("SOAPACTION", soapAction);
  http.sendHeader("Connection: keep-alive");
  http.sendHeader("Content-Length", soap.length());
  http.sendHeader("");                    // a blank line before the body
  http.sendHeader(soap);                  // add the body
  http.endRequest();                      // end the request
  Serial.println("request opened");

Two suggested solutions:

Either sendBody() simply calls sendHeader(), or sendBody() callas a blank sendHeader() to separate from the headers, then calls sendHeader() with the body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions