PHP HttpClient模拟登陆
2015-02-11 21:40
357 查看
这里面的参数,$xuehao,$mm,$zym就是验证码,学号,密码,$lt是登陆页面的隐藏信息。我们可以通过发fiddler查看
比如工大的模拟登陆:
也可以通过查看源代码 搜索<input
就会发现lt这个属性,然后我们如何获取其值呢?。。我们可以现在模拟登陆的界面获取,代码如下:
<?php
header("content-Type: text/html; charset=utf-8");
include_once("./httpClient.php");
$client = new httpClient("cas.nwpu.edu.cn");
$client->get("/cas");
$html = $client->getContent();
$header = $client->getHeaders();
print_r($header);
$nesoft = $header['set-cookie'];//neusoftnwpudcp=hTCsJbhWpmG5TVTzLcnsTNJVpjQrgwByvJyL42srRGvRZZH2Ldbr!1675837507
$nesoft = substr($nesoft, 15, 63);
$cookie = Array("neusoftnwpudcp"=>$nesoft);
$client->setCookies($cookie,true);
$client->get("/cas/Captcha.jpg");
$img = $client->getContent();
$file = fopen("Captcha.jpg", "w");
fwrite($file, $img);
fclose($file);
//$preg="/name=\"lt\" value=\"LT_nwpuapp[\d]+_-[\d]+-[\w]*/";
$preg = "/name=\"lt\" value=\"LT_nwpuapp[\d]+_-[\d]+-[\w]*/";
preg_match($preg, $html, $hidden);
$hidden = $hidden[0];
print_r($hidden);
//$preg="/LT_nwpuapp[\d]+_-[\d]+-[\w]+/";
$preg = "/LT_nwpuapp[\d]+_-[\d]+-[\w]+/";
preg_match($preg, $hidden, $hidden_value);
$hidden_value = $hidden_value[0];
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="index1.php">
账号:<input type="text" value="2013303461" name="xuehao" /><br/>
密码:<input type="password" value="043017" name="mm" /><br/>
验证码:<input type="text" value="" name="yzm" /><img src="Captcha.jpg"/><br/>
<input type="Submit" value="查询"/>
<input type="hidden" name="neusoftnwpudcp" value="<?php echo $nesoft;?>"/>
<input type="hidden" name="hidden_value" value="<?php echo $hidden_value;?>" />
</form>
</body>
</html>
上式是通过正则表达式,来描述的
模拟登陆有两种方法,HTTPClient和CURL两种方法,以上是HTTPClient,,,两种方法都不太熟,以后再多多练习吧
比如工大的模拟登陆:
也可以通过查看源代码 搜索<input
就会发现lt这个属性,然后我们如何获取其值呢?。。我们可以现在模拟登陆的界面获取,代码如下:
<?php
header("content-Type: text/html; charset=utf-8");
include_once("./httpClient.php");
$client = new httpClient("cas.nwpu.edu.cn");
$client->get("/cas");
$html = $client->getContent();
$header = $client->getHeaders();
print_r($header);
$nesoft = $header['set-cookie'];//neusoftnwpudcp=hTCsJbhWpmG5TVTzLcnsTNJVpjQrgwByvJyL42srRGvRZZH2Ldbr!1675837507
$nesoft = substr($nesoft, 15, 63);
$cookie = Array("neusoftnwpudcp"=>$nesoft);
$client->setCookies($cookie,true);
$client->get("/cas/Captcha.jpg");
$img = $client->getContent();
$file = fopen("Captcha.jpg", "w");
fwrite($file, $img);
fclose($file);
//$preg="/name=\"lt\" value=\"LT_nwpuapp[\d]+_-[\d]+-[\w]*/";
$preg = "/name=\"lt\" value=\"LT_nwpuapp[\d]+_-[\d]+-[\w]*/";
preg_match($preg, $html, $hidden);
$hidden = $hidden[0];
print_r($hidden);
//$preg="/LT_nwpuapp[\d]+_-[\d]+-[\w]+/";
$preg = "/LT_nwpuapp[\d]+_-[\d]+-[\w]+/";
preg_match($preg, $hidden, $hidden_value);
$hidden_value = $hidden_value[0];
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="index1.php">
账号:<input type="text" value="2013303461" name="xuehao" /><br/>
密码:<input type="password" value="043017" name="mm" /><br/>
验证码:<input type="text" value="" name="yzm" /><img src="Captcha.jpg"/><br/>
<input type="Submit" value="查询"/>
<input type="hidden" name="neusoftnwpudcp" value="<?php echo $nesoft;?>"/>
<input type="hidden" name="hidden_value" value="<?php echo $hidden_value;?>" />
</form>
</body>
</html>
上式是通过正则表达式,来描述的
模拟登陆有两种方法,HTTPClient和CURL两种方法,以上是HTTPClient,,,两种方法都不太熟,以后再多多练习吧
相关文章推荐
- httpclient/jsoup模拟登陆人人网
- HttpClient 模拟登陆,保持会话并进行后续操作
- java httpclient 模拟登陆京东
- 用PHP模拟登陆(引自http://www.tianjiaonet.com)
- HttpClient 模拟登陆知乎
- Java httpClient 正方教务管理系统模拟登陆,爬取学生成绩和培养计划
- HttpClient 模拟登陆百度 2015.10.21 JAVA
- httpclient模拟登陆,不支持https的问题
- HttpClient 模拟登陆百度 2015.10.21 JAVA
- Php模拟登录工具类 HttpClient
- 新浪模拟登陆 HttpClient 4 cookie rejected 问题
- 安卓HttpClient+Jsoup+Httpwatch模拟登陆正方教务获取信息
- HttpClient+Jsoup模拟登陆,解析HTML,信息筛选(广工图书馆)
- httpclient模拟登陆操作实现
- HttpClient4使用(模拟登陆)
- C#HttpClient或使用CookieContainer模拟登陆后HttpRequest不发送cookie的解决方法及原因
- 05_HttpClient_模拟登陆
- HTTPclient模拟登陆交大图书馆---图书馆客户端
- HttpClient 模拟登陆,保持会话并进行后续操作
- httpclient 模拟登陆