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 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私