0
청크 인코딩에 문제가 있습니다. 다음은 샘플 코드입니다.청크 인코딩이 작동하지 않습니다.
opts={
hostname: "httpbin.org",
path: '/post',
method: "POST",
headers: {
"Content-Type": "text/plain", // should default to chunked
'Connection': 'keep-alive',
},
};
var req = http.request(opts, function(res){
res.setEncoding('utf8');
res.on("data", function(data){
console.log(data);
});
});
req.write("hello");
req.end();
Data returned from httpbin:
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Connection": "close",
"Content-Type": "text/plain",
"Host": "httpbin.org",
"Transfer-Encoding": "chunked",
"X-Request-Id": "341e3bea-9c71-4b69-bff3-93cea7207c6d"
},
"json": null,
"origin": "119.xxx,xxx",
"url": "http://httpbin.org/post"
}
데이터가 비어있는 것으로 나타났습니다.
그러나 'Content-Length': 5,
을 opts.headers
에 추가하면 청크 분할 인코딩이 해제되고 데이터가 예상대로 "hello"가됩니다.
청크 분할 인코딩의 문제점은 무엇입니까?