Kreoda
27.12.2009, 02:05
<?php
function goto($url='', $post='', $ref='')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.25 (Windows NT 5.1; U; ru)');
curl_setopt($ch, CURLOPT_COOKIEJAR,"./cook.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE,"./cook.txt");
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
else {
curl_setopt($ch, CURLOPT_POST, 0);
}
if (!empty($ref)) {
curl_setopt($ch, CURLOPT_REFERER, $ref);
}
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function get($url) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_COOKIEFILE,"./cook.txt");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIEJAR,"./cook.txt");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0);
$res = curl_exec($ch);
echo $res;
curl_close($ch);
}
// Авторизуемся
$res = goto("http://xhtml.wap.mail.ru/cgi-bin/auth","Login=Ваш_Логин&Domain=mail.ru&Password=Ваш_пароль&page=","http://xhtml.wap.mail.ru/cgi-bin/splash_mail");
preg_match("#Location: (.*)#",$res,$m);
$str = explode("://",$m[0]);
// Формируем ссылку на папку Входящие
$link_1 = "http://".$str[1];
$link_1 = str_replace("start?back=1","msglist?folder=0",$link_1);
get($link_1);
?>
Почему-то браузер 400 Bad Request,а ссылку-то ведь правильно сформировал.Следовательно, и запрос должен быть верный(запрос гет).В чём проблема ?
function goto($url='', $post='', $ref='')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.25 (Windows NT 5.1; U; ru)');
curl_setopt($ch, CURLOPT_COOKIEJAR,"./cook.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE,"./cook.txt");
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
else {
curl_setopt($ch, CURLOPT_POST, 0);
}
if (!empty($ref)) {
curl_setopt($ch, CURLOPT_REFERER, $ref);
}
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function get($url) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_COOKIEFILE,"./cook.txt");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIEJAR,"./cook.txt");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0);
$res = curl_exec($ch);
echo $res;
curl_close($ch);
}
// Авторизуемся
$res = goto("http://xhtml.wap.mail.ru/cgi-bin/auth","Login=Ваш_Логин&Domain=mail.ru&Password=Ваш_пароль&page=","http://xhtml.wap.mail.ru/cgi-bin/splash_mail");
preg_match("#Location: (.*)#",$res,$m);
$str = explode("://",$m[0]);
// Формируем ссылку на папку Входящие
$link_1 = "http://".$str[1];
$link_1 = str_replace("start?back=1","msglist?folder=0",$link_1);
get($link_1);
?>
Почему-то браузер 400 Bad Request,а ссылку-то ведь правильно сформировал.Следовательно, и запрос должен быть верный(запрос гет).В чём проблема ?