【发布时间】:2012-10-08 23:37:27
【问题描述】:
我正在尝试在要求用户名和密码的安全 URL 上触发 HTTP GET 请求。当我从浏览器中使用它时这很好,但我不确定如何使用 PHP 来做到这一点。
我尝试过使用这两种方法:
1) 按照此处的建议使用 Curl:Make a HTTPS request through PHP and get response
2) 使用此处建议的 file_get_contents:How to send a GET request from PHP?
但是第一个没有给我任何回复。第二个给了我以下错误:
failed to open stream: HTTP request failed
这是我的 curl 代码:
$url="https://xxxxx.com";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
对于 file_get_contents:
$url="https://xxxx.com";
$response=file_get_contents($url);
echo $response;
该 URL 将为我正在测试的 API 返回一个 XML 响应。有人能指出我正确的方向吗?
谢谢!
【问题讨论】:
-
您可能会混淆访问限制(例如基本身份验证和 co)和 https - 您确定服务器需要 https 吗?如果你需要基本身份验证,你必须告诉 curl 给网络服务器一个用户名和密码。
标签: php xml curl https http-get