* 1.how to send HTTP POST request(post string); * 2.how to send HTTP POST request(post array) * @author iPHPJungle * @since 2015/07/01 周三(wed) */ include '../iHttp.php'; $iH = new iHttp(); // $iH->enableProxy = true; // $iH->setProxy('localhost', 7777); $iH->ar_cookie = array('ckkdk1' => 111, 'ck_3i3i' => 2, 'ckejofwe' => '==222=222'); $base_url = 'http://www.yourdomain.com/'; # do NOT forget the end slash # type-1:form $formdata = array('username' => 'PHPJungle', 'password' => 'xxxx'); # type-2:form $formdatastr = http_build_query($formdata); $html = $iH->post($base_url, $formdata); $html = $iH->post($base_url, $formdatastr); echo $html; # Raw HTTP POST Request // POST http://www.yourdomain.com/ 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.yourdomain.com // Accept: */* // Accept-Encoding: deflate, gzip // Referer: // Connection: Keep-Alive // Cookie: ckkdk1=111; ck_3i3i=2; ckejofwe===222=222 // Content-Length: 32 // Content-Type: application/x-www-form-urlencoded // username=PHPJungle&password=xxxx
$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 $back = $iH->posts($urls_post, $urls_post_data); // 异步方式:return array (asyn method) $back = $iH->posts($urls_post, $urls_post_data, false); // 同步方式:return array (sync method) // 6. 笔者在iHttp中添加了静态方法,方便大家查看执行相同任务时同步和异步的性能差别,调用方法:(test the time your code cost with calc_begin and calc_end ) $iH::calc_begin(); //@todo add your codes :) $iH::calc_end(); // 7. 设置连接超时时间(set_connect_timeout) $iH->set_connect_timeout(10); // set_connect_timeout to 10secs