I'm trying to calculate the response size (content length) of a XMLHttpRequest. This works fine when 'Content-Length' is in the response header. However, by using Chrome Developer Tool, I noticed that when Transfer Encoding is chunked (when response is over 36 KB), I'm not able to get response size.
How can I estimate the response size when Transfer Encoding is chunked in JavaScript?
let req = new XMLHttpRequest(); req.open("POST", "localhost:8080/hello"); req.setRequestHeader("Content-type", "application/json"); req.responseType = "json"; req.onloadend = (e) => { console.log(e.total); }; req.send({ world: "!"});
null. Why are you setting a Content-Type? No data at all is not valid JSON.