当前位置: 代码迷 >> PHP >> PHP模拟POST aspx页面不成功,该怎么解决
  详细解决方案

PHP模拟POST aspx页面不成功,该怎么解决

热度:200   发布时间:2016-04-28 20:08:31.0
PHP模拟POST aspx页面不成功
下面实例返回 是  0|访问限制!请重新加载页面
应该放回 -2|车牌号码错误


<?
/************************************************************************
Name: POST 测试程序 Vesion: 1.0 Date: 2004-08-05 
*************************************************************************/
$keyimg=$_POST['keyimg'];
if($keyimg){
????$flag = 0;
???? //要post的数据 
????$argv = array(
????????'action'=>'Illagel', 
????????'back4'=>'3248', 
????????'headno'=>'粤', 
????????'no'=>'LA9532', 
????????'type'=>'02', 
????????'validate'=>$keyimg????
????????); 
????//构造要post的字符串 
????foreach ($argv as $key=>$value) { 
????????if ($flag!=0) {
????????????$params .= "&"; 
????????????$flag = 1; 
????????} 
????????$params.= $key."=";
????????$params.= urlencode($value); 
????????//$params.= $value; 
????????$flag = 1; 
????} 
????echo $params;
????$length = strlen($params);
???? //创建socket连接 
????$fp = fsockopen("www.gdhzcgs.com",80,$errno,$errstr,10) or exit($errstr."--->".$errno); 
????//构造post请求的头 
????//$header = "POST /Illegal.aspx HTTP/1.1\r\n"; 
????$header = "POST /Ajax.aspx HTTP/1.1\r\n"; 
????$header .= "Host:www.gdhzcgs.com\r\n"; 
????$header .= "Referer:www.gdhzcgs.com/Illegal.aspx\r\n"; 
????$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
????$header .= "Content-Length: ".$length."\r\n"; 
????$header .= "Connection: Close\r\n\r\n";
????//添加post的字符串 
????$header .= $params."\r\n"; 
????//发送post的数据 
????fputs($fp,$header); 
????$inheader = 1; 
????while (!feof($fp)) {
????????$line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据 
????????if ($inheader && ($line == "\n" || $line == "\r\n")) {
???????????? $inheader = 0; 
????????} 
????????if ($inheader == 0) { 
????????????echo $line; 
????????} 
????} 
????fclose($fp);
}
else{
 echo 'keyimg=空';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>网上车管所</title>
</head>
<body onload="SetTitle()">
<form id="aspnetForm" action="" method="post" name="aspnetForm">
<input name="keyimg" type="text" />
<img src="http://www.gdhzcgs.com/CheckCode.aspx" >
<input name="submit" type="submit" value="查找" />
</form>
</body>
</html>

------解决方案--------------------
Request Headers Value
(Request-Line) POST /Ajax.aspx HTTP/1.1
x-requested-with XMLHttpRequest
Accept-Language zh-CN
Referer http://www.gdhzcgs.com/Illegal.aspx
Accept */*
Content-Type application/x-www-form-urlencoded
Accept-Encoding gzip, deflate
User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host www.gdhzcgs.com
Content-Length 69
Connection Keep-Alive
Cache-Control no-cache
Cookie ASP.NET_SessionId=rimtcb55pc2gcgurkaimgi45; CNZZDATA3614737=cnzz_eid=42940778-1343020353-&ntime=1343020353&cnzz_a=0&retime=1343020354714&sin=&ltime=1343020354714&rtime=0

有Cookie呀..
  相关解决方案