dqwh1208 2019-04-03 05:41
浏览 90
已采纳

如何在guzzle查询构建期间将“管道”添加到get参数中

I'm using an api that has a "range" parameter that can apply to several different parameter items. The range i'm focusing on is "price". I'm using guzzle in laravel and according to the api documentation, the query for this particular parameter should be written like this "&range_facet=price|500|2500|250"...this is broken down into the minimum, maximum, and interval values of the price range parameter. That's not necessarily important to this question. When i try and run this query as is, i get nothing returned. When I remove that particular parameter, i get values but obviously they're not filtered the way i want them to be. When i run this in Insomnia, the pipes are replaced by "%7C", which is obviously (obviously?) not interpreted by the api as it's not how it's waiting for the GET request to be made. How can I insert the pipes into the query so that it calls the correct way?

I've tried to create an additional nested array with the price value being broken up into key value pairs but that didn't work either.

'range_facets' => ['price'['start'=>'500', end=>'2500', 'interval'=>'250']],
$client = new Client();
      $result = $client->request('GET', "http://api.example.com", [
    'headers' => [
        'Host' => 'example-host',
        'Content-Type'     => 'application/json'
    ],
    'query' => [
      'api_key' => 'my_api_key',
      'range_facets' => 'price|500|2500|250',
      'year' => $year,
      'latitude' => '30.170222',
      'longitude' => '92.01320199',
      'radius' => 500,
      'start' => 0,
      'rows' => 50
    ]
]);

I'd like to filter my prices but I need the pipe to be able to do it.

  • 写回答

1条回答 默认 最新

  • doushen2154 2019-04-04 12:06
    关注

    This is exactly how it should be. %7C should be decoded on the server side to | automatically (about query string encoding).

    I bet the issue is in different place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛