What about the garbled data obtained by node's http.request?

serer.js
I would like to use the following method to act as a proxy. I can get the data of the test environment locally and debug it locally.
options-related configuration

let request = http.request(options, function(response){
                response.on("data", function(chunk) {
                    data = data + chunk
                })
                response.on("end", function() {
                    try {
                        data = JSON.parse(data)
                    } catch(err) {
                        console.log(err)
                    }
                    res.json && res.json(data) || (res.body = data)
                })
            })

            request.on("error", function(e) {
                console.log("Error", e)
            })
            request.write(postdata)
            request.end()

it is normal for json, to take data from other websites in this way.
but taking the data from our company"s test environment becomes:

clipboard.png

like this.
it is normal to request a connection directly in the browser.


take a look at the encoding format from the initial message, which may be gb2312 or gbk. If so, you need to transcode

.
Menu