N
N
NeTLeaDeR2020-03-20 22:59:03
Node.js
NeTLeaDeR, 2020-03-20 22:59:03

How to decode HTTP response?

Hello. I'm trying to break up the application to make an autoregister and stumbled upon the following problem.

Weak in mat. parts, so please do not throw slippers if something is wrong somewhere;)

The problem is this: I make a POST request for registration
(I use nodeJS and the request module), the request is executed fine (I draw this conclusion because the mail a letter arrives with a "confirmation code"), but in the body of the response there is such a shorthand:
c719Db40.jpg

Before that, I sniffed the Fiddler'om application, there was the same problem, but after googling, I found that it occurs due to the fact that the response lacks a header
Content-Encoding:deflateand Fiddler doesn't know that he needs to do something else with this line. Accordingly, with a script that substitutes this header in all the responses of the desired host, I defeated this problem and everything is ok in Fiddler.

Actually the question itself: as far as I understand, the request body is simply compressed by the deflate algorithm and I need to somehow return it to the human form, how can I do this?

Well, the request code itself:

request.post({
    url: Endpoint,
    headers: {
        'Content-Type': 'application/json',
        'User-Agent': UserAgent
    },
    body: authRequest
}, (err, response, body) => {
    if(err) {
        return console.log('[AUTH] Ошибка регистрации: ' + err);
    }
    console.log(body);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Blyshko, 2020-03-21
@nekt

Send `Accept-encoding: identity` in the request and you might not have to decode anything
https://developer.mozilla.org/en-US/docs/Web/HTTP/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question