Strange characters in the body after requesting a response

I use NodeJS and Request to publish JSON and get the result with the data in it.

I installed this request using Postman and I get JSON data that is fully readable.

{
  "d": {
    "__type": "Qvision.WoningenModule.Lib.aanbodcollection",
    "testOutput": "",
    "filter": null,
     ...
     etc.
  }
}

I created a code snippet from Postman so that I can put it on my NodeJS server with the requested request.

When I try to run a request on my node server with a encoded body.

        `I %&/m {J J  t `$ؐ@       iG#) *  eVe]f@ 흼  {    {    ; N'   ?\fdl  J ɞ!   ?~|?"~ G     ~ ߿ ^ =  '.      V by /  f 2?/& ,[N ٴ* | R  F y ~ nW  ^  ϋ    - eI Vm   Z       | ѣ  "   b } h |+4   ~QWU    >      Ge6 ˆ _  "    ^o  bF HO<  GM[gYK   E \/   G[  UN^  eN  ͊ Ң  A_? n   Ƙ˼Z       f@  z Qb=)  Zѯ  | Fo+z .~m. z  墚 %  ̫ uMs y1 x uA    >   Ų  / fZ  h    "    Y    ͐Ƣ@w   w    5+s;     1  2 $  G  ?      Ų b O ˬ    9   ~P-gy L  |i/     Q  $_  H E  _ |Y     <s8  /  8     $  ?~  C J#{ 3      o6ķ{ wSU4    YK   j L D K D  K kan '$    uQ  ĺ ]     J4Z      O      O?      O~ '  ~  d? N {   G  {;    ݽ    *  }j   O @ N ^= ڊ>+ Dƍ ]%QM wjy         ! )          g   ? &    R    i | 6  N U v  o >    ;    `  ?xpp  "f        ; v  U sy~V     w o m~ :#       x Ӄ  ß      `g  A $     > G z    b   ߧ$ ; ; _ Mȼ lv `  po vxNB{Y WP?     {{ j  t   g ˽    C >1j  G         jE   ?   Ux /ww   b2 DI   ݧ  aK  k5   }n]   | tgw  : ;;   J   S O  > O  /   \x =  ?  / >B    O   ;  :ݻ G  9 % v< h䱶^:  {| KF    {     o 4    . M < =  w     I    +M  >i { ݽ  = |oߨb3ޟ .    v     j  n z|x  *1u? ~JF    à      c&}mK س   f   t   &ELF   e  > Y  ? .fUճ ;  oh    o ?  #  si )Z    9      ~  />      Ҍ  }   KR Cf    =    6 $3      Y5 ~    vw Hż lvHf|       Rh s T  gnj    ݿo{ Y1 ԉ o   { `g_ kv̸  >y  >4   ϒ ;}@    l Ϛ   O*l S# 1ey    uЌ     ' ۆ  o ʤu "җ  O~ , {     [Xo1  FQ    t   F sk   h |  d       =  ٦   > )F  =ܷif3   .) J)_ ~VͶ  >E  ΰ 9 Y     `  N  f  {   ώ  z Oi    턺   O?}`    1 ~   ;v6a= ̶ )-   6  7g 7tI   } T   Mf      *ofy  ZbY  . B  M   g l  3 ?ͷ; "   n @_|sv{       ݦo    ߟ @ m\" w    o?=  ,  s; v  7  Y r !%   c  Y   [R7    h ڭX   ) }      ޣ   ~ p ٱ ~ (ͱc  d g        [1  ٱ ~ H K  h  NHT  u  5  w      e   ɢ LZt )=s~  C^ v      Ɓ!K       F x c՟W- I   U4 5Ɠl88 ױ ;    ᅬx      5I R84% J s  | <   ʚS  ӇdQ  O    W   g GR{ ~ =   r ׇ 0    UL  bv        &  >%" ^v  )  }, h ?+v  n    33    q ?Z8~H|   gɊ{} k   C# ?kF      c     ^6 W  9,2 ]      0 5   X. D 0  &; SD(       ڈ    5F     1 ?  < j  #   Ů QψS m    | %      / _ <~     9 e^^  nה   
 ϕ)   ރO ?  G ~ v v /3   i         g WZP}p   p  g ?ʑ    DT    l #   {fWz  1 ^ ~ {  X    r  ]
 vMw ώ)     ? p`2 0 ?K       m ?k  둖 | gz i   σ |    J    /YF  R G?k  }b   #$߿1C~g  C C      /    %K 9

Like it. In Postman, the data is good, but in node it is not. How can it be? There is nothing wrong with my request:

var request = require("request");

var options = { method: 'POST',
  url: '****',
  headers: 
   { 'postman-token': '****',
     cookie: '****',
     'accept-language': 'nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4',
     'accept-encoding': 'gzip, deflate, br',
     referer: '****',
     'content-type': 'application/json; charset=UTF-8',
     'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
     'x-requested-with': 'XMLHttpRequest',
     origin: '****',
     accept: 'application/json, text/javascript, */*; q=0.01',
     'cache-control': 'no-cache',
     pragma: 'no-cache',
     'content-length': '1035',
     connection: 'keep-alive',
     host: '****' },
  body: '{"****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************}',
  //encoding: null
   };

request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});

The .log console provides the data specified in the second code snippet.

Can someone explain to me what is happening and why it works in a postman, but not in Node?

+6
2

, , , ( gzip), , , . gzip: true request(), request body, .

'accept-encoding': 'gzip, deflate, br' headers, gzip.

+12

, accept-encoding , 95,74

, , 168,8

var request = require("request");

var options = {
    method: 'GET',
    url: 'xxxxxxxxxx',
    headers: {
        'cache-control': 'no-cache',
        Connection: 'keep-alive',

        cookie: 'my_cookie',
        Host: 'xxxxxx',
        'Postman-Token': 'a9f0a67f-9733-4419-aa78-04f5a97cbe76,214f1c4f-4df4-48f6-89e7-9805b9ceca40',
        'Cache-Control': 'no-cache',
        Accept: '*/*',
        'User-Agent': 'PostmanRuntime/7.15.0'
    }
};

request(options, function (error, response, body) {

    console.log(body)
});

, , -, .

:

:

0

Source: https://habr.com/ru/post/1649150/


All Articles