缘由么,看我源码,你猜

因为COOKIE需要存放在浏览器而不是服务器中,所以不用curl自带的CURLOPT_COOKIESESSION设置

直接打开CURLOPT_HEADERCURLOPT_HTTPHEADER头传递

<?php
header('Content-type:text/html;charset=gb2312');

if($_SERVER['REQUEST_METHOD']!=="POST"){
$requestUrl = 'jwc2.0000000.edu.cn:8080';
$ch = curl_init();
$timeout = 5;
$HTTP_SESSION= 'ASP.NET_SessionId='. $_COOKIE["jwc2"];
$headers = array(
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language:zh-CN,zh;q=0.8',
'Cookie:'. $HTTP_SESSION,
'Host:jwc2.0000000.edu.cn:8080',
'Origin:http://jwc2.0000.edu.cn:8080',
'Referer:http://jwc2.00000.edu.cn:8080/',
);
curl_setopt ($ch, CURLOPT_URL, $requestUrl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
$file_contents = curl_exec($ch);
preg_match('/ASP.NET_SessionId=(.*?);/',$file_contents,$cook);
$cookie=$cook[1];
if($cookie != '') {setcookie("jwc2", $cookie, time()+360);}
curl_close($ch);
$msg = str_replace('verifycode.aspx', 'code.php', $file_contents);
$msg = preg_replace('/<table ([\s\S]*)<\/map>
<\/div>/', ' ', $msg);
echo strstr($msg,"<HTML>");
}
//print_r($_POST);
if($_SERVER['REQUEST_METHOD']=="POST")
{$url = 'jwc2.0000.edu.cn:8080';
$post_data = $_POST;
$timeout = 5;
$HTTP_SESSION= 'ASP.NET_SessionId='. $_COOKIE["jwc2"];
$headers = array(
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language:zh-CN,zh;q=0.8',
'Cookie:'. $HTTP_SESSION,
'Host:jwc2.0000.edu.cn:8080',
'Origin:http://jwc2.0000.edu.cn:8080',
'Referer:http://jwc2.0000.edu.cn:8080/',
'Upgrade-Insecure-Requests:1',
'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
//curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
if($post_data != ''){
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents1 = curl_exec($ch);
curl_close($ch);
//setcookie("jwc2", $cookie, time()+360);
//echo '<br>'. $cookie;
//echo $HTTP_SESSION;
$file_contents1 = preg_replace('/<table ([\s\S]*)<\/map>
<\/div>/', ' ', $file_contents1);
echo $file_contents1;
}
?>

 

更新于:2017-11-25