function http_request($request_url, $type='get', $data=array()) {
$url = parse_url($request_url);
$host = $url['host'];
$path = $url['path'];
$query = $url['query'];
$path .= $query ? '?'. $query : '';
$parameter = $sep = '';
if (!empty($data)) {
foreach ($data as $key => $value){
$parameter .= $sep . urlencode($key) .'='. urlencode($value);
$sep = '&';
}
}
if (strtolower($type) == 'get') {
$path .= $parameter;
$out = "GET {$path} HTTP/1.1\r\n";
$out .= "Accept: */*\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n";
$out .= "Host: {$host}\r\n";
$out .= "Connection: Close\r\n\r\n";
} else {
$out = "POST {$path} HTTP/1.1\r\n";
$out .= "Accept: */*\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n";
$out .= "Host: {$host}\r\n";
$out .= 'Content-Length: '.strlen($parameter)."\r\n";
$out .= "Connection: Close\r\n\r\n";
$out .= $parameter;
}
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp) {
fwrite($fp, $out);
fclose($fp);
}
}