Esempio n. 1
0
 static function calc_end()
 {
     self::$time_end = time();
     $tpl = '<div style="font-family:consolas;border:2px solid #eee;padding:5px;">It cost %s s</div>';
     $timespam = self::$time_end - self::$time_begin;
     echo sprintf($tpl, $timespam);
 }
<?php

/**
 * 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]
Esempio n. 3
0
<?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登陆
Esempio n. 4
0
<?php

/**
 * Introduction list:How to build HTTP POST Request
 * 		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
Esempio n. 5
0
 * Introduction list:
 * 		1.how to send HTTP GET request;
 * 		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>';