2010-10-23 118 views
1

我一直在努力编写一个脚本,它会自动将我登录到我学校的网络中,检查我想要进入的课程是否不再完全满足,并且如果某个位置已打开,请为我注册课程。然而,我只是在登录过程中遇到了很大的麻烦。PHP CURL:不允许完整处理HTTP头文件?

基本上,我一直在查看登录时发送的标题并尝试复制它们。问题是我不断收到一个错误,提示“HTTP/1.1 400 Bad Request Content-Type:text/html日期:2010年10月23日18:42:20 GMT连接:close内容长度:42 错误的请求名称)”。

我猜它与主机参数有关我的设置与实际是不同的(我将它设置为elion.psu.edu,但是当从脚本中查看标题时,已经改回到grantbachman.com,脚本在那里托管)。我想最好只是为了向你展示。 头的开始,我想创建:

https://elion.psu.edu/cgi-bin/elion-student.exe/submit 

POST /cgi-bin/elion-student.exe/submit HTTP/1.1 
Host: elion.psu.edu 

这说明了,当我运行我的脚本头的开头:

http://myDomain.com/myScriptName.php 

GET /elionScript.php HTTP/1.1 
Host: myDomain.com 

基本上,第一行是不同的,主机名是不同的,它说我发送我的信息与GET变量,而不是一个POST变量(即使我将curlopt_post设置为true)。我基本上寻找任何帮助改变这个信息,使服务器接受我的脚本。我刚刚从创意中脱颖而出。谢谢。

哦,这里是我使用的代码:

$data = array(
    "$userIDName" => '********', 
    "$passName" => '********', 
    "$submitName" => 'Login+to+eLion', 
    'submitController' => '', 
    'forceUnicode' => '%D0%B4%D0%B0', 
    'sessionKey' => "$sessionValue", 
    'pageKey' => "$pageKeyValue", 
    'shopperID' => ''); 

$contentLength = strlen($userIDName . '=*********&' . $passName . '=********&' . $submitName .'=Login+to+eLion&submitController=&forceUnicode=%D0%B4%D0%B0&sessionKey=' . $sessionValue . '&pageKey=' . $pageKeyValue . '&shopperID='); 

$ch = curl_init("https://elion.psu.edu/cgi-bin/elion-student.exe/submit"); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_COOKIE,'sessionKey="$sessionValue";pageKey="$pageKeyValue";BIGipServerelion_prod_pool="$prodPoolValue"'); 
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
    'Host: elion.psu.edu', 
    'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10', 
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
    'Accept-Language: en-us,en;q=0.5','Accept-Encoding: gzip,deflate', 
    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
    'Keep-Alive: 115', 
    'Referer: https://elion.psu.edu/cgi-bin/elion-student.exe/launch/ELionMainGUI/Student', 
    "Cookie: sessionKey=$sessionValue; pageKey=$pageKeyValue; BIGipServerelion_prod_pool=$prodPoolValue", 'Content-Type: application/x-www-form-urlencoded', 
    "Content-Length: $contentLength")); 
$contents2 = curl_exec ($ch); 

I'T也可能需要注意的是,当我运行该脚本,没有任何信息的“保持活动:115”下面的线当我查看标题时显示。

+0

我们可能需要查看实际的代码。 – mellowsoon 2010-10-23 19:41:28

+0

好的,我只是添加了代码,希望有所帮助。 – 2010-10-23 21:19:52

+0

我在尝试获取一些JSON数据时遇到了问题,您的CURLOPT_HTTPHEADER帮了我很多!非常感谢你! – Bagata 2013-09-06 00:55:15

回答

0

看来它缺少你的问题的一些代码,但试试这个:

1-保存您的证书服务器

2 - 上试试这个代码

$pg = curl_init(); 
// Set the form data for posting the login information 
$postData = array(); 
$postData["username"] = $username; 
$postData["password"] = $password; 

$postText = ""; 

foreach($postData as $key => $value) { 
$postText .= $key . "=" . $value . "&"; 
} 

curl_setopt($pg, CURLOPT_URL, $YOUR_URL); 
curl_setopt($pg, CURLOPT_POST, true); 
curl_setopt($pg, CURLOPT_POSTFIELDS, $postText); 
curl_setopt($pg, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($pg, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($pg, CURLOPT_CAINFO, getcwd() . '/web'); //web is the exported certificate 


//curl_setopt($pg, CURLOPT_VERBOSE, true); // for debug 
//curl_setopt($pg, CURLOPT_RETURNTRANSFERT, true); // if you want a ouput 
curl_setopt($pg, CURLOPT_COOKIEJAR, "cookies.txt"); 
curl_setopt($pg, CURLOPT_COOKIEFILE, "cookies.txt"); 
curl_setopt($pg, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt($pg, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($pg, CURLOPT_COOKIE, session_name() . '=' . session_id()); 

if(($response = curl_exec($pg)) === false) { 
     echo '*Curl erro' . curl_error($pg) . "\n"; 
} 

curl_close($pg) 

$ YOUR_URL:HTTPS:/ /elion.psu.edu/cgi-bin/elion-student.exe/launch/ELionMainGUI/Student

使用动态名称的表单使其不像“用户名”和“密码”那样简单。检查网站以了解“好”的一个。

不要忘记像在postData数组中那样添加其他隐藏字段并更新cookie部分。

+0

感谢您的帮助,但我遇到了另一个问题。我以前从未与证书或会话混淆,但我访问了该网站并将证书下载到我的服务器。但是,我收到此错误:“SSL证书问题,请验证CA证书是否正常。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败”。我采取了更简单的方法,并将VERIFYPEER设置为false。这工作,但我继续点击他们的Session Expired页面。你知道什么会导致它这样做,或者我做错了什么? – 2010-10-24 03:26:20

+0

嗯,我认为你做错了什么,因为它没有工作。从我的角度来看,我无法做一些测试,因为我没有访问权限,而且它看起来像是感性内容,所以我很难帮助你。 – malletjo 2010-10-24 03:42:32