$ar_null = array_fill(0, $num, null); $url_get = 'http://www.baidu.com/s?wd=PHPJungle'; // 模拟百度Get搜索 $tpl_get = 'http://www.baidu.com/s?wd=%s'; $urls_get = array_map(function ($i) { global $tpl_get; return sprintf($tpl_get, rand(0, 100)); }, $ar_null); $url_post = 'https://passport.weibo.cn/sso/login'; // 模拟sinaPOST登陆 $post_data = array('username' => '*****@*****.**', 'password' => '2vfhfuewew'); $urls_post = array_fill(0, $num, $url_post); $urls_post_data = array_fill(0, $num, $post_data); // Demo start // 4.1 http_get $iH->get($url_get); // !important: return string or false // 4.2 multi-http_get $iH->gets($urls_get); //默认异步方式请求,return array (default send http request with asyn) $iH->gets($urls_get, false); // init OPs $iH->reffer = 'https://passport.weibo.cn/signin/login?entry=mweibo&res=wel&wm=3349&r=http%3A%2F%2Fm.weibo.cn%2F'; $iH->origin = 'https://passport.weibo.cn'; // 或者下面的2选1 $iH->requestHeader = array('Origin' => 'https://passport.weibo.cn'); $back = $iH->post($url_post, $post_data); // return string or false echo $iH->getLastError(); // 打印错误信息(print last error msg) // 5.2 multi-http_post
# $iH->port= '8888'; $base_url = 'http://www.demo.com:8080'; # enable proxy:ture $iH->enableProxy = true; $iH->setProxy('localhost', 7777); # set request cookie with string $iH->cookie = 'a=1; b=2'; # method-1:build cookie with string(delimiter is "; ") # set request cookie with array $ar_cookie = array('a' => 1, 'b' => 2, 'c' => 3); $iH->ar_cookie = $ar_cookie; # method-2:build cookie with array # set referer $iH->reffer = 'http://www.referer.com'; # set Origin[method-1] $iH->origin = 'http://www.phpjungle.com'; # set Origin[method-2] $iH->requestHeader['Origin'] = 'http://www.phpjungle.com'; # set other header with requestHeader $iH->requestHeader['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'; $html = $iH->get($base_url); // the Raw HTTP Request like this // GET http://www.demo.com:8080/ HTTP/1.1 // User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36 // Host: www.demo.com:8080 // Accept-Encoding: deflate, gzip // Referer: http://www.referer.com // Proxy-Connection: Keep-Alive // Cookie: a=1; b=2; c=3 // Origin: http://www.phpjungle.com // Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
* 2.get last error msg; * 3.get response headers(array) * 4.get response cookie(string or array) * 5.get response body(string) * * @author PHPJungle * @since 2015/07/01 周三(wed) */ include '../iHttp.php'; $url = 'https://www.google.com/'; // $url = 'https://www.baidu.com/'; // $url = 'http://www.phpjungle.com/'; iHttp::calc_begin(); $iH = new iHttp(); # response body $html = $iH->get($url); # return:string or false when fails # last error string $errormsg = $iH->getLastError(); # response headers(array) $res_ar_header = $iH->res_ar_header; # response cookie(string) $res_cookie = $iH->res_cookie; # response cookie(array) $res_ar_cookie = $iH->res_ar_cookie; var_dump('response headers(array):', $res_ar_header); echo '<hr>'; var_dump('response cookie(string):', $res_cookie, PHP_EOL, '<hr>'); echo '<hr>'; var_dump('response cookie(array):', $res_ar_cookie); echo '<hr>';