getting an external webpage with curl, password and username
im retreiving a webpage as a string using curl and php
code:
$ch = curl_init();
// the external url
$url = 'http://cursos.puc.cl/eaa220a-1/correo/main.html';
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt ($ch, CURLOPT_开发者_如何学PythonHTTPHEADER, array (
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// get the source code
$html = curl_exec($ch);
however the webpage, asks username and passowrd to enter. I have no idea on how to manage this. Thx!
From here:
$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);
You can read more about curl_setopt()
here.
精彩评论