//Header headers for default impersonation Private function_defaultheader () {$header= "user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.2.12) gecko/20101026 firefox/3.6.12\r\n "; $header. = "accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; $header. = "accept-language:zh-cn,zh;q=0.5\r\n"; $header. = "accept-charset:gb2312,utf-8;q=0.7,*;q=0.7\r\n"; return $header; }
Private functionPost$url,$post _data=Array(),$timeout=5,$header="") { $header=Empty($header) ? Self::_default_header ():$header; $post _string=Http_build_query($post _data); $header. = "Content-length:".strlen($post _string); $opts=Array( ' http ' =Array( ' Protocol_version ' = ' 1.0 ',//HTTP protocol version (default to http1.0 if php5.2 is not specified)' Method ' = ' POST ',//How to get' Timeout ' =$timeout,//Timeout period' Header ' =$header, ' content ' =$post _string) ); $context=stream_context_create($opts); //to resolve an interface timeout $cnt=0; while($cnt< 3 && ($str[Email protected]file_get_contents($url,false,$context))===FALSE) $cnt++; return $str; }
File_get_contents Post Data