PHP的卷曲 - 访问网址为http身份验证(需要帮助) [英] php curl - accessing url with http authentication (need help)

查看:194
本文介绍了PHP的卷曲 - 访问网址为http身份验证(需要帮助)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTTP认证的问题。因为它需要HTTP认证我不能让这个网址的内容。

I have a problem in HTTP Authentication. I couldn't get the content of this url because it need http auth.

code:

<?php

$url = "http://www.abcdefg.com/12345/";

$username = 'username';
$password = 'password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$out = curl_exec($ch);

print "error:" . curl_error($ch) . "<br />";
print "output:" . $out . "<br /><br />";

curl_close($ch);

?>

问题是:
相反,展示真实的内容,它显示的302发现,该文件已经搬到这里。

我试过的http://用户名:password@www.abcdefg.com/12345/,不能正常工作

I've tried "http://username:password@www.abcdefg.com/12345/", doesn't work.

当访问这个URL(1),弹出窗口要求输入用户名和密码。但弹出窗口是从另一个URL(2)(SSO一个认证服务器)。如果通过认证。那么(1)再次回来到URL。在这个时候,我可以访问此网址(1)中的内容。

When accessing this url(1), a popup window ask for username and password. but the popup window is from another url(2)(a sso authentication server). if pass the authentication. then it gets back to url(1) again. at this time, I can access the content of this url(1).

我使用萤火虫直接从浏览器访问的网址会收到以下消息:

I use firebug get the following message by accessing the url directly from browser:

第1步

URL: GET http://www.abcdefg.com/12345/
Status: 302 Found
Protocol: http

第2步

URL: GET https://www.ssoauth.com/obrareq.cgi?wh=xxx wu=xxx wo=xxx rh=http://www.abcdefg.com ru=/12345/
Status: 302 Redirect
Protocol: https

第3步

URL: GET http://www.abcdefg.com/obrar.cgi?cookie=xxxxxxxxxxxxxxx
Status: 302 Found
Protocol: http

第四步

URL: GET http://www.abcdefg.com/12345/
Status: 200 OK
Protocol: http

然后显示的内容...

Then display the content…

这是什么做的饼干吗?
如何使用PHP卷曲阅读的内容?

推荐答案

您必须设置:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

这会使卷曲服从302并产生一个额外的要求。

This will make cURL obey the 302 and generate an additional request.

这篇关于PHP的卷曲 - 访问网址为http身份验证(需要帮助)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆