无法使用 Zend_Http_Client 存储第二个客户端请求的会话
我正在向同一客户端发送多个请求。 zend_Http_Client 无法重定向,因为我们的网站提供了 javascript 重定向。从该 javascript 中,我获取了重定向 url 并再次调用客户端,现在我的访问被拒绝。这是因为我无法存储第一个客户端请求的会话。
我正在使用以下代码。
$client = new Zend_Http_Client(
$loginUrl,
array(
'keepalive' => true,
'timeout' => 1000
)
);
$response = $client->request()->getBody();
$redirectUrl = $this->_getResponseRedirectUrl($response);
$client->resetParameters();
$client->setUri($redirectUrl);
$response = $client->request()->getBody();
$resultUrl = $this->_getResponseRedirectUrl($response);
任何人都可以告诉我如何存储第二个请求的会话。
I'm sending multiple requests to same client. zend_Http_Client not able to redirect because our site giving a javascript redirect. And from that javascript I'm getting the redirect url and again calling the client , now I'm getting access denied. This is beacuse I'm not able to store the session from the first client request.
I'm using the following code..
$client = new Zend_Http_Client(
$loginUrl,
array(
'keepalive' => true,
'timeout' => 1000
)
);
$response = $client->request()->getBody();
$redirectUrl = $this->_getResponseRedirectUrl($response);
$client->resetParameters();
$client->setUri($redirectUrl);
$response = $client->request()->getBody();
$resultUrl = $this->_getResponseRedirectUrl($response);
Can anybody tell me how to store the session for the second request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在尝试以下步骤之前,请确保您的服务器身份验证基于会话 cookie。
解决方案对我有用:
您需要将第一次休息中的cookie添加到第二次请求中。在这种情况下,服务器将您的第二个请求视为经过身份验证的请求。在登录站点后的响应中,您的 cookie 将具有以下一组值,例如 cookie-name、cookie-value、Expiration Date、Path、Secure 和 HTTPOnly。从 cookie 字符串中分解 cookie-name 和 cookie-value
登录响应后的示例会话 Cookie:
按照以下模式创建新的 cookie 字符串以用于进一步的服务器通信:
添加一个方便的方法来从 zend_http_client“Set-cookie”数组创建 cookie 字符串。
使用 Zend_Http_Client 发出连续请求:
这里我删除“$client->resetParameters();”因为您没有使用“$client->setParameterGet()”设置任何 GET 参数(POST 也相同)
如果使用“$client->setParameterGet()”或“$client->setParameterPost()”使用“$client->resetParameters();”在设置第二个 uri 之前。
$client->resetParameters() 接受布尔值:
Before trying the following steps make sure your server authentication is based on session cookies.
Solution Worked for me:
You need to add cookies from the first repose to the second request. In this case server consider your second request as authenticated one.In the response after login to the site your cookie will be having following set of values like cookie-name,cookie-value,Expiration Date, Path, Secure and HTTPOnly. From the cookie string explode cookie-name and cookie-value
Example Session Cookie after login response:
Create new cookie string for further server communication in the following pattern:
Adding a handy method to create cookie string from zend_http_client "Set-cookie" array.
Using Zend_Http_Client making consecutive requests:
Here I am removing "$client->resetParameters();" because you are not setting any GET Params using "$client->setParameterGet()"(Same for POST as well)
If using "$client->setParameterGet()" or "$client->setParameterPost()" use "$client->resetParameters();" before setting second uri.
$client->resetParameters() accepts boolean values:
实际上,Zend_Http_Client 提供了一种非常简单的方法来完成您所做的事情,无需在这里重新发明轮子。
在这里阅读更多内容: http://framework.zend.com/manual/en /zend.http.cookies.html
Actuall, Zend_Http_Client provides a very simple way to do what you've done, no need to reinvent the wheel here.
Read more here: http://framework.zend.com/manual/en/zend.http.cookies.html