1

在我请求特定的 GraphQL api 之前,我已经能够完全请求 npm 包。这是我的帖子请求功能如下:

var options = {
    url: "",
    body: "",
    headers: {
      'User-Agent': 'Sneaks-API',
      'Content-Type': 'application/json',
      'Host': 'graphql.stadiumgoods.com',
      'Content-Length': 466

    }
  };

  module.exports = {
    getProductInfo: function(shoe, callback){
          options.body = '{"operationId":"sg-front/cached-a41eba558ae6325f072164477a24d3c2","variables":{"initialSearchQuery":"'+ shoe.styleID +'","initialSort":"RELEVANCE","filteringOnCategory":false,"filteringOnBrand":false,"filteringOnMensSizes":false,"filteringOnKidsSizes":false,"filteringOnWomensSizes":false,"filteringOnApparelSizes":false,"filteringOnGender":false,"filteringOnColor":false,"filteringOnPriceRange":false},"locale":"USA_USD"}'
          options.url = 'https://graphql.stadiumgoods.com/graphql'
          request.post(options,
            function (error, response, data) {    
                if (!error && response.statusCode == 200) {
                    var json = JSON.parse(data);
                    console.log(json);
                    callback();
                }
            }
        );

但是,每当我运行它时,出于某种原因,我都会不断收到此错误。

{ 错误:在 TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) 读取 ECONNRESET 错误:'ECONNRESET',代码:'ECONNRESET',系统调用:'read'}

我尝试在 Postman 上使用相同的标头执行相同的发布请求,并且效果很好。有关如何解决此问题的任何想法?谢谢。

4

0 回答 0