使用Zend_Http_Client进行身份验证 [英] authentication using Zend_Http_Client
问题描述
我正在尝试使用Zend_Http_Client在需要身份验证的网站上进行简单的发布请求.一切似乎都是正确的,但是我仍然出现You are not authorized to view this page
错误.任何想法可能是什么问题?我确定用户名和密码正确
$client = new \Zend_Http_Client('http://ncmcrm/sales_summary/activity_range.asp');
$client->setHeaders('WWW-Authenticate', 'Negotiate');
$client->setParameterPost(array(
'from_day' => 1,
'from_month' => 1,
'from_year' => 2012,
'to_day' => 31,
'to_month' => 1,
'to_year' => 2012,
'user_id' => '{BCDF3313-9DBA-40E7-9CD8-02332F72A64F}'
));
$client->setAuth('******', '*****', \Zend_Http_Client::AUTH_BASIC);
$response = $client->request('POST');
print_r($response->getBody());
这是我感兴趣的POST请求在Firebug中得到的内容:
Response Headers
Connection close
Content-Length 4431
Content-Type text/html
Date Thu, 08 Mar 2012 19:13:11 GMT
Server Microsoft-IIS/5.0
WWW-Authenticate Negotiate NTLM
Request Headers
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Content-Length 120
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie ASPSESSIONIDAAQSBCBQ=FEEOKMDAANCMKLGBKDBNKLHE
Host ncmcrm
Referer http://ncmcrm/sales_summary/sales_summary.asp
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
您正在将WWW-Authenticate标头设置为协商",但随后您尝试使用$ this-> setAuth设置Basic Auth标头./p>
假设Web服务器实际上将允许基本身份验证,则删除$client->setHeaders('WWW-Authenticate', 'Negotiate');
行应该可以.
I'm trying to use Zend_Http_Client to make a simple post request on a site that requires authentication. Everything seems to be correct but I'm still getting a You are not authorized to view this page
error. Any ideas what the problem might be? I'm certain the username and password are correct
$client = new \Zend_Http_Client('http://ncmcrm/sales_summary/activity_range.asp');
$client->setHeaders('WWW-Authenticate', 'Negotiate');
$client->setParameterPost(array(
'from_day' => 1,
'from_month' => 1,
'from_year' => 2012,
'to_day' => 31,
'to_month' => 1,
'to_year' => 2012,
'user_id' => '{BCDF3313-9DBA-40E7-9CD8-02332F72A64F}'
));
$client->setAuth('******', '*****', \Zend_Http_Client::AUTH_BASIC);
$response = $client->request('POST');
print_r($response->getBody());
Here's what I get in Firebug for the POST request that I'm interested in:
Response Headers
Connection close
Content-Length 4431
Content-Type text/html
Date Thu, 08 Mar 2012 19:13:11 GMT
Server Microsoft-IIS/5.0
WWW-Authenticate Negotiate NTLM
Request Headers
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Content-Length 120
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie ASPSESSIONIDAAQSBCBQ=FEEOKMDAANCMKLGBKDBNKLHE
Host ncmcrm
Referer http://ncmcrm/sales_summary/sales_summary.asp
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
You're setting the WWW-Authenticate header to "Negotiate", but then you're trying to set Basic Auth headers with $this->setAuth.
Assuming the web server will in fact allow basic auth, Removing the $client->setHeaders('WWW-Authenticate', 'Negotiate');
line should work.
这篇关于使用Zend_Http_Client进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!