0

I'm having issues with my node-fetch (specifically, node-fetch-cookies library). I'm supposed to get a string returning from a POST request like:

post_enc=9820CE922B01A166253A29384BA535D7BD08D94FC826A28C67403D19A45AF1CDF5E93DF40C029870DC0D8BD0DFBC9F36C521AF23E7D47CA2156BF917F3CC90B15A848873C3E851170E1C6738C570362E020BCB57FF189044EC611EA6FE2B843A69E248705008E9F2C1CF02030EADA9&post_chk=4A19

BUT I keep getting this instead:

post_enc=9820CE922B01A166253A29384BA535D7BD08D94FC826A28C67403D19A45AF1CDF5E93DF40C029870DC0D8BD0DFBC9F36C521AF23E7D47CA2156BF917F3CC90B15A848873C3E851170E1C6738C570362E020BCB57FF189044EC611EA6FE2B843A69E248705008E9F2C1CF02030EADA9DF4B6694940F35BB80FC9A4E9C6EEA57F08D858648E7979CCF83ADDDA8023E3E2893B6D2A59E86BA9531124251B43042F6F88A924E1B68C876967E2EBA29EEE34C4FD14C70BF0FDBC1A05B70FAC0476916F5C15F9136464D7187045EB>�022343040FB667B00AF2EAA230F90B00FD0E05A70A7102DE856FCB56656CFAB4FEF2C2139048B9CBB5370A500B2893623B61781↑☻¶�♀☻C�

I have tried removing any Accept-Encoding / Content-Encoding headers and I have tried to decode it using zlib but nothing seems to work.

Here's the exact code:

/** @type {any} */
        let headers = {
            'Content-Type': 'text/plain; charset=UTF-8',
            'Content-Encoding': 'gzip, deflate, br', // I've tried removing this...
            'Connection': 'keep-alive',
            'Accept': '*/*',
            'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
            'Accept-Encoding': 'gzip, deflate, br', // I've tried removing this...
            ...cfg?.headers,
        };
        let cookieJar = null;
        
        // Set the session cookie if the last Response had it.
        if(this.SessionInfo.SessionCookie != "" && !isLogin) {
            cookieJar = new CookieJar();
            cookieJar.addCookie(this.SessionInfo.SessionCookie, uri);
            headers = { ...headers, "Set-Cookie": this.SessionInfo.SessionCookie };
        }

        // Make the request.
        cfg = { ...cfg, headers, compress: true };
        const res = await fetch(cookieJar, uri, cfg);
tzuleger
  • 29
  • 3
  • 1
    my guess would be econding ,maybe iso 8859 vs utf-8. – erik258 Oct 02 '22 at 21:55
  • Unfortunately, even using "unescape(encodeURIComponent(...))" (or any variation of those functions), I don't get anything of what it should look like. It should just be a hexadecimal string entirely. – tzuleger Oct 02 '22 at 22:22
  • Have you looked at [a diff](https://i.stack.imgur.com/Yyvjd.png)? It's about twice as long and it replicates everything perfectly up to the `&`. – H.B. Oct 02 '22 at 22:30
  • @H.B. What I plugged in there was just an example, it doesn't actually reflect the actual body I should be getting. This code worked before and I got everything exactly as it should have, but then I added a few functions to my code and suddenly this started popping up. I tried going back to an old commit and it was just broke still, so I have no idea what changed. – tzuleger Oct 02 '22 at 22:38
  • Why do you think the problem is in the client code, not the API? – Barmar Oct 02 '22 at 22:47
  • @Barmar it could very well be the API, the device I'm working with is designed horribly, but I had it working initially and I never touched my HTTP request code, suddenly this started happening. – tzuleger Oct 02 '22 at 22:50
  • There's nothing in your code that will change the data being returned. – Barmar Oct 02 '22 at 22:52
  • So I looked more into the device I am interacting with and it turns out that for some reason the SDK associated with it broke because none of their commercial products are working either (which worked before). – tzuleger Oct 03 '22 at 01:23

0 Answers0