Loopback API:响应受到压缩

By simon at 2018-02-07 • 0人收藏 • 72人看过

如何解码“内容编码:gzip,gzip”使用环回? 我已经创建了其他连接器来获得以下ap的响应一世 : “https://rest.cricketapi.com/rest/v2/match/dev_season_2014_q3/balls/?access_token= ******* *”。 我是特别针对许多网站 https://github.com/strongloop/loopback/issues/1551但我没有得到 解。弗洛翼是代码: * /服务器/ datasources.json **

    {
  "Datasource": {
    "host": "127.0.0.1",
    "port": 27017,
    "database": "dbname",
    "name": "dbname",
    "connector": "mongodb"
  },
  "cricketApi": {
    "name": "cricketApi",
    "baseURL": "https://rest.cricketapi.com/rest",
    "crud": false,
    "connector": "rest",
    "operations": [
      {
        "functions": {
          "auth": [
            "app_id"
          ]
        },
        "template": {
          "method": "POST",
          "url": "https://rest.cricketapi.com/rest/v2/auth/",
          "headers": {
            "accepts": "application/json",
            "content-type": "application/json"
          },
          "form": {
              "access_key": "*********",
              "secret_key": "**********",
              "app_id": "{^app_id}",
              "device_id": "********"
          }
        }
      },
      {
        "functions": {
          "ballbyball": [
            "access_token"
          ]
        },
        "template": {
          "method": "GET",
          "url": "https://rest.cricketapi.com/rest/v2/match/dev_season_2014_q3/balls/",
          "headers": {
            "accepts": "application/json",
            "content-type": "application/json"
          },
          "query": {
              "access_token": "{access_token}"
          }
        }
      },
      {
        "functions": {
          "getships": []
        },
        "template": {
          "method": "GET",
          "url": "http://swapi.co/api/starships/",
          "headers": {
            "accepts": "application/json",
            "content-type": "application/json"
          }
        }
      },
      {
        "functions": {
          "schedule": []
        },
        "template": {
          "method": "GET",
          "url": "https://rest.cricketapi.com/rest/v2/match/dev_season_2014_q3/balls/?access_token=*********",
          "headers": {
            "accepts": "application/json",
            "content-type": "application/json",
            "content-encoding": "gzip"
          }
        }
      }
    ]
  }
}
以下api工作,但输出gzip压缩:
{
    "functions": {
      "schedule": []
    },
    "template": {
      "method": "GET",
      "url": "https://rest.cricketapi.com/rest/v2/match/dev_season_2014_q3/balls/?access_token=2s151429438441649s961198289187901461",
      "headers": {
        "accepts": "application/json",
        "content-type": "application/json",
        "content-encoding": "gzip"
      }
    }
  }
它给出了以下输出: [![输入图片说明 这里](https://i.stack.imgur.com/racCN.png)(https://i.stack.imgur.com/racCN.png) “” \ u001f \ B \ u00006yZ \ u0002Mo0 \ FJS \ u001f(萨夫\ u0018P \ u0014,QL中号濏ӤY\ u0018uX {H 小号\ u0014 | L+Cn1ĵK;E7ʦF\ TB \ U0001 \ t8nS \ u0016%)EZXa \ u0015 $ ٱhsekv> 7igu)#T} \ U0003 \ ;; HMڀ\u0018˪ڮր\ F |; TUY @ \ u000f} \b�\\���\u0011\tC��\t)\u0016ED��\u0015�*\u0012Y\u001c�Ȩ�\u0007�J�ޞ�Lb\u0011�\u0010�:�8�r��qa\n�\u0011J�\u0010\u001b�\u0005)8\u0016�\u00178�\"°R�\u0011���\u0018�\"\u0013Z_\u0006\\�~�\b�\"N4Va(��\u0014ʂ�d*�3m��T�[�c�s�#�\u0005����2��p��\b\u0015�2c�3�ɂb%\"NM�\fU\f]N��z��6�����\u000f~���m�Jm; YQ> QD {c3iu \ u0017 \ [ ?\ U0002 @릝\ NFU \ u0005 \ u001fzn;吴\ u000eh5 \ü000fQ \ u001fV \u0000EӕphOO \ u0010 \˚F\ u0019ڱ\ n \ u000b /:\ u0007r \ u0001D \ BX \ u0006 / LB \ u0017 \ u0013N \ u0012 \ u0003E \ u0015!Q / Z +!Ӯ��ڗ�'�\u0012

o��\u0001�u媷\u0015Ͳ�\u0007}¦Y����\u0000z/�M����smyݣ�7�\u001b9H=�u\rb���{�aU���\u000b}�;YYs[\r���\u0004�I�� �ޢ}]F \ n \ u000f \ tHg8j} HRG \ u0000的| \u0017Cζ{P҄\ u0000Jur(P߅ \ u0015(թ\ u001c \ FOD \吨/ LN \ u000foO \ u001e>〜F3 ^ X \ u0005L \ u001dcoys \ u001c | A&d \ u0004p_ \ u001e'b> B; C ϳGG7'8β\ u001fOy \ u001a7u; / {\ u001e $Ё0< 小号 我也试着运行* DEBUG =压缩节点。来看压缩如何 用来。你可以看看屏幕截图下面给出 [![输入图片说明 这里](https://i.stack.imgur.com/vYdIg.png)(https://i.stack.imgur.com/vYdIg.png) 我也尝试在server.js文件中使用压缩=>

var compression = require('compression');
app.use(compression());
并在 / server / middleware.json中添加以下几行:
"compression": {
  "params": { "threshold": 512 }
}
但它不适合我。 不过,我知道它如何在PHP中使用下面的代码:
    header('Content-Type: application/json');
    $ch = curl_init();
    $curlConfig = array(
    CURLOPT_URL            => "https://rest.cricketapi.com/rest/v2/match/dev_season_2014_q3/balls/?access_token=2s151429438441649s961*******",
    CURLOPT_POST           => true,
    CURLOPT_ENCODING       => "gzip",  
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => "Accept: application/json"
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);

echo $result;
这将是伟大的和帮助如果我在回送中获得解决方案。谢谢!

1 个回复 | 最后更新于 2018-02-07
2018-02-07   #1

我瘦这个链接将帮助你... Ryan Knell发布了这个答案 [node.js - 简单的http请求与gzip / deflate 压缩](HTTPS://stackoverflow.com/questions/8880741/node-js-easy-http- 请求与 - 用gzip放气压缩) 我们只需要添加“gzip:true“在我的要求,因为要求已经 支持 https://github.com/request/request

登录后方可回帖

Loading...