封装一个function,以便复用。 支持https,或者http的get或者post。 function httpURLfeedback($url,$request_type,$time_out = "60") { $arr = parse_url($url); $transports = ""; $port = 0; $host = $arr['host']; $query = $arr['query']; $path = $arr['path']; if($urlarr["scheme"] == "https") { $transports = "ssl://"; $port = "443"; } else { $transports = "tcp://"; $port = "80"; } $fp=@fsockopen($transports.$host,$port,$errno,$errstr,$time_out); if(!$fp) { die("ERROR: $errno - $errstr<br />/n"); } else { $out = ""; if($request_type == 'get'){ $out .= "GET $path?$query HTTP/1.1/r/n"; $out .= "Host: $host/r/n"; $out .= "Connection: Close/r/n/r/n"; }else { $out .= "POST $path HTTP/1.1/r/n"; $out .= "Host: $host/r/n"; $out .= "Content-type: application/x-www-form-urlencoded/r/n"; $out .= "Content-length: ".strlen($query)."/r/n"; $out .= "Connection: Close/r/n/r/n"; $out .= $query. "/r/n/r/n"; } fwrite($fp,$out); while(!feof($fp)) { echo @fgets($fp, 1024); } fclose($fp); } } httpURLfeedback("http://www.baidu.com/s?wd=wwe",'get');