* Introduction list:How to Build http request header * 1.how to add cookie,referer,origin for http request headers; * 2.how to add other http request headers; * @author PHPJungle * @since 15.07.02 周四(Thursday) * @abstract Some times we need build http request with cookie,referer,Origin,etc, * or we will not get the target http response */ include '../iHttp.php'; $iH = new iHttp(); # set PORT # $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';
<?php // 接口文档:(API Document) // 1.实例化 (1.new objct) $iH = new iHttp(); // 2.使用代理[如果使用的话](set proxy if necessary) $iH->enableProxy = true; // 默认为false (Default value is false) $iH->setProxy('127.0.0.1', 7777); // 3.设置Cookie,UserAgent,Origin,RequestHeader (set Cookie,UserAgent,Origin,other Request header infos) $iH->cookie = 'a=1; b=2'; // 方式1:字符串类型,如果有多个请用'; '分开(method-1:you can build cookie with string) $iH->ar_cookie = array(); // 方式2:数组类型,键值对形式(method-2:build cookie with array) $iH->origin = ''; // string $iH->userAgent = ''; // string $iH->requestHeader = array(); $num = 10; // 测试次数 $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登陆