Set content length of request based on content in node
Problem
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?
Problem courtesy of: vinod
Solution
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
}
};
Solution courtesy of: vinayr
Discussion
View additional discussion.