我想通過證書到一個網站,所以我可以使用它的file_get_contents提取一些數據,但它不工作,我得到一個空白頁,所以任何想法這裏有什麼錯?在PHP中傳遞證書cURL幫助
<?php
$username="[email protected]";
$password="Koin";
$url="confluence.rogersdigitalmedia.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$str= file_get_contents("confluence.rogersdigitalmedia.com/display/prodsupport/Team+Calendar");
echo $str;
?>
這是新的代碼,它仍然沒有工作停留在當我得到的內容登錄屏幕....
<?php
$username="[email protected]";
$password="Koin";
$url="confluence.rogersdigitalmedia.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Replaced due to special chars in url for username and pass
//curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_USERPWD, urlencode($username) . ':' . urlencode($password));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo file_get_contents('http://confluence.rogersdigitalmedia.com/exportword?pageId=1114407');
?>
新的代碼:我知道$url
是URL,對此我必須登錄,但我怎麼樣在$data
?我知道這是我的登錄信息,但我怎麼把它(例如,<用戶名>空間<密碼>)?
<?php
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
HTTP響應頭文件的外觀如何?你從服務器獲得什麼狀態? – 2011-06-08 14:40:50