Warning: file_get_contents(http://news.163.com/special/00013C0B/gedixw.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in F:\wamp\www\jxcms\test.php on line 2
调试欢乐多
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //获得返回内容,但不需要直接输出到页面上
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //时间延迟
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$output = curl_exec($ch); //执行,并接收返回的内容
curl_close($ch);
echo $output;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
$tmp = parse_url($url);
$host = $tmp['host'];
$port = $tmp['port'];
$path = $tmp['path'];
$tmp['query'] && $path .= '?' . $tmp['query'];
if (empty($port))$port = 80;
elseif ($tmp['scheme'] == 'https') $port = 443;
elseif ($tmp['scheme'] == 'http') $port = 80;
$fp = @fsockopen($host, $port, $errno, $errstr);
$data = '';
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$tmp = "GET $path HTTP/1.1\r\n";
$tmp .= "Host: $host\r\n";
$tmp .= "User-Agent: $user_agent\r\n";
$tmp .= "Connection: Close\r\n\r\n";
fwrite($fp , $tmp);
while (!feof($fp)) $data .= fgets($fp, 1024);
$data = trim(substr($data, strpos($data, "\r\n\r\n") + 4));
fclose($fp);
}echo $data;这样可以,不知道是不是过段时间也会被封
{
$query_str = preg_replace('/^&/', '', $query_str);
$url = $url.'?'.$query_str;
$context = array('http' =>
array('method' => 'GET',
'header' => 'User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 2.0.50727)'
)
);
$contextid = stream_context_create($context);
$sock = fopen($url, 'r', false, $contextid);
if($sock)
{
$result = '';
while (!feof($sock))
{
$result .= fgets($sock, 4096);
}
fclose($sock);
}
return array(0, $result);
}
$arr = get_request('http://news.163.com/special/00013C0B/gedixw.html', '');
print_r( $arr );测试通过
再不行
看看后台用Java写个呢