vinod
vinod

Reputation: 8420

Set content length of request based on content in node

How to set the content length of the request based on the content?

For example:

POST /Display HTTP/1.0
Content-Type: application/json
Content-Length: 125

{"QueryReq":
  {
    "Tid": "Tid-123456",
    "SessionId" : "1350711351232058820" 
  }
}

On posting this request in telnet I need to press enter many times till the content length is 125 that is empty chunks are received in the server. How can set the content length automatically based on the request content?

Upvotes: 1

Views: 7465

Answers (1)

vinayr
vinayr

Reputation: 11234

Set Content-Length header

var data = querystring.stringify({
  "QueryReq": { "Tid": "Tid-123456", "SessionId" : "1350711351232058820" }
});

var options = {
    host: xxx,
    port: xxx,
    ----
    ----
    headers: {
      'Content-Length': data.length
    }
};

Upvotes: 2

Related Questions