[英]Completely disable redirection for Guzzle
Guzzle6
has one pretty option: allow_redirects
. Guzzle6
有一个不错的选择: allow_redirects
。 If setting this option to false
value, Guzzle blocking redirect if response code like 302
or Headers
has Location
param. 如果将此选项设置为
false
值,则在响应代码(例如302
或Headers
具有Location
参数的情况下,Guzzle将阻止重定向。
But there is one problem. 但是有一个问题。 If redirect sends by client – Guzzle doesn't notice this.
如果重定向是由客户端发送的,则Guzzle不会注意到这一点。 For example:
例如:
We have some URL http://example.com/
that redirected to page http://redirected.com/
. 我们有一些URL
http://example.com/
重定向到页面http://redirected.com/
。 Send request with help Guzzle: 发送请求与帮助Guzzle:
$oClient->request('POST', 'http://redirected.com/', [
'form_params' => $aFormData,
'cookies' => (new CookieJar($aPrepareCookie)),
'debug' => true,
'allow_redirects' => false
]);
Suppose that redirect.com
has index.php
like this: 假设
redirect.com
具有如下的index.php
:
<?php
header('Location: http://www.example.com/');
?>
In this case, the redirection will be blocked from Guzzle. 在这种情况下,重定向将不受Guzzle的限制。
Now, let's see this redirect example: 现在,让我们看一下这个重定向示例:
<?php
echo '<script>window.location = "http://www.example.com/";</script>';
?>
Here we have a problem because this is client side redirect and his can't affect the Headers
, Therefore Guzzle
can't track HTTP Status Code or Location value. 这里我们有一个问题,因为这是客户端重定向,并且他不能影响
Headers
,因此Guzzle
无法跟踪HTTP状态代码或位置值。
So, how i can solve this problem and find solution? 那么,我如何解决这个问题并找到解决方案?
Thanks for help! 感谢帮助!
As previous posters have said, Guzzle will not execute the javascript. 正如以前的海报所说,Guzzle不会执行javascript。
Your problem could easily be solved by utilizing Guzzle Middleware . 您可以通过使用Guzzle中间件轻松解决您的问题。
Within the middleware: 在中间件中:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.