【问题标题】:Guzzle 6 - How to pass query to redirectsGuzzle 6 - 如何将查询传递给重定向
【发布时间】:2017-10-04 19:28:53
【问题描述】:

我正在努力寻找是否有办法让 Guzzle 将查询传递给重定向。所以如果我说

          $res = $client->request("GET", "https://google.com", [

                    'allow_redirects' => true,
                    'timeout' => 2000,
                    'query' => ['foo'=>'bar'],
          ]);

让我们说(出于某种奇怪的原因)谷歌重定向到 https://somewhere-else.com,我希望我的 foobar 查询也被传递到该 URL

https://somewhere-else.com?foo=bar

希望对此有所帮助。

谢谢

【问题讨论】:

  • 不容易,你问的是真正的非标准行为。
  • 你这么认为吗?大多数重定向是将用户从现在过时的地址带到页面的新位置,所以在大多数情况下,新位置不需要查询字符串吗?
  • 当然,但为您提供准确的重定向 URI 是服务器的工作。如果需要,它应该代表您传播查询参数。

标签: php redirect query-string guzzle6


【解决方案1】:

Guzzle 中没有标准机制可以做到这一点,因为(正如 @Calimero 已经说过的)HTTP 规范不假设这种行为。

但是你可以复制和修改the RedirectMiddleware,Guzzle 用来处理allow_redirects 选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-29
    • 2017-06-25
    • 2017-03-08
    • 2022-12-02
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 2016-05-26
    相关资源
    最近更新 更多