0

I'm using nodejs to send http request to a server, and get http response from it(the http response body is encrypted, while the http header is normal). The response body will be written to a file. But I find the response body is different from what the server sent.

This is what I've done:

request.post({
    headers: {'content-type':'application/json'},
        url:'url-to-server',
        body:data-to-send
    }, function(error, response, body){         
    if(!error && response.statusCode==200){
        fs.writeFile(path-to-file,body,function(err){
        });
    }
});

The problem is, some byte values are replaced by ef bf bd

Server Send:   
    f5 cb b6 48 77 b6 26 6a d2 4c d8 d9 ...
Received data: 
    ef bf bd cb b6 48 77 ef bf bd 26 6a ...

Any ideas?

Sunson
  • 88
  • 1
  • 8

1 Answers1

1

I've found that ef bf bd occurs when it tries to use utf-8 encoding. So I want to recieve raw data without encoding.

And I found this question about getting binary content, according to this link, i add encoding:null in my code, see below:


    request.post({
        headers: {'content-type':'application/json'},
        url:'url-to-server',
        encoding:null,
        body:data-to-send
    }, function(error, response, body){         
        if(!error && response.statusCode==200){
            fs.writeFile(path-to-file,body,function(err){
            });
        }
    });

And now the received data is correct.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347
Sunson
  • 88
  • 1
  • 8