php curl digest,php curl with digest返回两个响应

如果对标头使用-I选项,则看起来curl具有相同的行为:

curl -I --digest -u root:somepassword http://localhost/digest-test/

收益:

HTTP/1.1 401 Authorization Required

Date: Fri, 31 May 2013 13:48:35 GMT

Server: Apache/2.2.22 (Ubuntu)

WWW-Authenticate: Digest realm="Test Page", nonce="9RUL3wPeBAA=52ef6531dcdd1de61f239ed6dd234a3288d81701", algorithm=MD5, domain="/digest-test/ http://localhost", qop="auth"

Vary: Accept-Encoding

Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK

Date: Fri, 31 May 2013 13:48:35 GMT

Server: Apache/2.2.22 (Ubuntu)

Authentication-Info: rspauth="4f5f8237e9760f777255f6618c21df4c", cnonce="MTQ3NDk1", nc=00000001, qop=auth

Vary: Accept-Encoding

Content-Type: text/html;charset=UTF-8

X-Pad: avoid browser bug

要获得第二个标题,您可以尝试这个(不是非常优化的解决方案):

$ch = curl_init();

// set url

curl_setopt($ch, CURLOPT_URL, "http://localhost/digest-test/");

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);

curl_setopt($ch, CURLOPT_USERPWD, "root:test");

// first authentication with a head request

curl_setopt($ch, CURLOPT_NOBODY, 1);

curl_exec($ch);

// the get the real output

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_HTTPGET, 1);

$output = curl_exec($ch);

echo $output;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值