代码拉取完成,页面将自动刷新
<?php
interface Proto
{
// 连接url
function conn($url);
// get查询
function get();
// post查询
function post();
// 关闭连接
function close();
}
class Http implements Proto
{
//请求行、请求头信息、请求主体信息
protected $url = null;
protected $fh = null;
protected $line = array();
protected $version = 'HTTP/1.1';
protected $header = array();
protected $body = array();
protected $response = '';
protected $errno = -1;
protected $errstr = '';
public function __construct($url)
{
$this->conn($url);
$this->setHeader('Host: ' . $this->url['host']);
}
// 请求行
protected function setLine($method)
{
$this->line[0] = $method. ' ' . $this->url['path'] . '?' . $this->url['query'] . ' ' . $this->version;
}
// 请求头信息
public function setHeader($headerline)
{
$this->header[] = $headerline;
}
// 请求主体信息
protected function setBody($body)
{
// $this->body = array_merge($this->body,$body);
$this->body[] = http_build_query($body);
}
function conn($url)
{
$this->url = parse_url($url);
// 判断端口
if(!isset($this->url['port']))
$this->url['port'] = 80;
$this->fh = fsockopen($this->url['host'],$this->url['port'],$this->errno,$this->errstr,3);
}
public function get()
{
$this->setLine('GET');
$this->request();
return $this->response;
}
public function post($body = array())
{
$this->setLine('POST');
//content-type&&content-length
$this->setHeader('Content-type: application/x-www-form-urlencoded');
// 设计主体信息,跟GET不一样的地方
$this->setBody($body);
$this->setHeader('Content-length: ' . strlen($this->body[0]));
$this->request();
return $this->response;
}
// request里面合并请求数组
public function request()
{
$req = array_merge($this->line, $this->header, array(''), $this->body,array(''));
$req = implode(PHP_EOL, $req);
// echo $req;die;
fwrite($this->fh, $req);
while(!feof($this->fh))
{
$this->response .= fread($this->fh,1024);
}
$this->close();
// return $this->response;
// var_dump($this->response);
}
function close()
{
fclose($this->fh);
}
}
require('./http.class.php');
$http = new Http('https://www.joinquant.com/user/login/doLogin');
$http->setHeader('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
$http->setHeader('Accept-Encoding: gzip, deflate');
$http->setHeader('Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3');
$http->setHeader('Connection: keep-alive');
$http->setHeader('Cookie: Hm_lvt_c7849bb40e146a37d411700cb7696e46=1450578346,1450591704; member_id=20803098; member_name=sherlockowen_qq; mgroupId=93; pass_hash=0b4a81656fd19e44165acee8ebbb1b4d; rememberme=true; uchome_auth=8333FURQDypWf%2BTDBYM52Xg9nMWGA6XJpkPgAHBt9u1P1ZTDEHBeSAlp524uHrRuSwm4l7R2n%2BuxECzK0fMAqD%2BchBs4NQ; uchome_loginuser=sherlockowen_qq; CNZZDATA1479=cnzz_eid%3D1888860155-1450577385-http%253A%252F%252Fwww.verycd.com%252F%26ntime%3D1450587438; __utma=248211998.1163897337.1450578504.1450587423.1450591718.3; __utmz=248211998.1450591718.3.2.utmcsr=verycd.com|utmccn=(referral)|utmcmd=referral|utmcct=/search/entries/%E7%87%95%E5%8D%81%E5%85%AB; sid=f1be7b600541e84b1c8df9283a1f15ac32b69693; Hm_lpvt_c7849bb40e146a37d411700cb7696e46=1450591704; uchome_sendmail=1; __utmb=248211998.2.10.1450591718; __utmc=248211998; __utmt=1');
$http->setHeader('Host: home.verycd.com');
$http->setHeader('Referer: http://home.verycd.com/cp.php?ac=pm');
$http->setHeader('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0');
$msg = array(
'formhash'=>'5e5cb85a',
'message'=>'dindidngdhh',
'pmsubmit'=>'true',
'pmsubmit_btn'=>'发送',
'refer'=>'http://home.verycd.com/space.php?do=pm&filter=newpm',
'username'=>'罗本爱范佩西_sina',
);
file_put_contents('./re.html', $http->post($msg));
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。