简体   繁体   English

Node.js请求主体有一些额外的填充

[英]Node.js request body has some extra padding

I am making a POST request in nodejs which returns protobuf that I need to pass to another function that will use it as the body of another request. 我在nodejs发出POST请求,该请求返回protobuf ,我需要将其传递给另一个函数,该函数将其用作另一个请求的主体。

The problem is, when I log the returned body from the request, it seems to have some extra bytes at the front like these (Base64 encoded) H4sIAAAAAAAAAAFxPY7C 问题是,当我记录从请求返回的body ,似乎前面有一些额外的字节,例如这些(Base64编码) H4sIAAAAAAAAAAFxPY7C

I've tried getting the body as a raw buffer and also as base64 but these extra bytes are always there, yet they are not there when I proxy the initial POST request. 我尝试将主体作为原始缓冲区以及作为base64但是这些额外的字节始终存在,但是当我代理初始POST请求时它们不存在。

I am making the request like this: 我正在发出这样的请求:

var requestParams = 
{
  uri: 'https://www.myurl',
  method: 'POST',
  encoding: 'base64',
  timeout: 4000,
  headers: 
  {
    'User-Agent': 'My Request',
    'Accept-Encoding': 'gzip'
  },
  body: myBody,
  tunnel: false // Used for proxy
};

var requestCompletion = function(error, response, body)
{
    console.log(error);
    response ? console.log(response.statusCode) : null
    console.log('RESULT: ' + body + '\n\n\n');

    if (!error && response.statusCode == 200) 
    {
        // Success
        nextFunction(body);
    }
    else
    {
        errorFunction(error + ' : ' + response.statusCode);
    }
}

request(requestParams, requestCompletion);

Can you please try with making gzip parameter true: 您能否尝试使gzip参数为true:

var requestParams = 
{
   uri: 'https://www.myurl',
   method: 'POST',
   encoding: 'base64',
   timeout: 4000,
   gzip: true,
   headers: 
          {
          'User-Agent': 'My Request',
          'Accept-Encoding': 'gzip'
          },
    body: myBody,
   tunnel: false // Used for proxy
   };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM