您好,登錄后才能下訂單哦!
/** * 發(fā)送一個(gè)異步http協(xié)議的Get請(qǐng)求,不用關(guān)心結(jié)果 * @param $url * @param $errno * @param $errstr * @param $time_out */ static public function getAsn($url,$errno='',$errstr='',$time_out = 5) { //移除url中的空格,如果可以格式化url,或許會(huì)更好 $url = str_replace(' ', '', $url); $arr = parse_url($url); $arr['port'] || $arr['port'] = 80; $fp = fsockopen($arr['host'],$arr['port'],$errno,$errstr,$time_out); if(!$fp) { return $errno." ".$errstr; } $arr['query'] && $arr['query'] = '?'.$arr['query']; $out = "GET ".$arr['path'].$arr['query']." HTTP/1.1\r\n"; $out .= "Host: ".$arr['host']."\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp,$out); fclose($fp); } /** * 異步post * @param $url * @param $post_arr * @param $errno * @param $errstr * @param $time_out */ static function postAsn($url,$post_arr,$errno = '',$errstr='',$time_out = 5) { $arr = parse_url($url); $arr['port'] || $arr['port'] = 80; $fp = fsockopen($arr['host'],$arr['port'],$errno,$errstr,$time_out); if(!$fp) { return $errno." ".$errstr; } $post_data = ""; if($post_arr){ //在這里還可以使用 http_build_query() 函數(shù),將post的內(nèi)容編碼 foreach ($post_arr as $key => $val){ $post_data .= urlencode($key) ."=". urlencode($val)."&"; } $post_data = substr($post_data, 0,-1); } $data_len = strlen($post_data); $arr['query'] && $arr['query'] = '?'.$arr['query']; $out = "POST ".$arr['path'].$arr['query']." HTTP/1.1\r\n"; $out .= "Host: ".$arr['host']."\r\n"; $out .= "Content-type:application/x-www-form-urlencoded\r\n"; $out .= "Connection: Close\r\n"; $out .= "Content-Length:$data_len\r\n\r\n"; $out .= $post_data."\r\n"; fwrite($fp,$out); fclose($fp); }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。