我一直在努力编写一个脚本,它会自动将我登录到我学校的网络中,检查我想要进入的课程是否不再完全满足,并且如果某个位置已打开,请为我注册课程。然而,我只是在登录过程中遇到了很大的麻烦。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”下面的线当我查看标题时显示。
我们可能需要查看实际的代码。 – mellowsoon 2010-10-23 19:41:28
好的,我只是添加了代码,希望有所帮助。 – 2010-10-23 21:19:52
我在尝试获取一些JSON数据时遇到了问题,您的CURLOPT_HTTPHEADER帮了我很多!非常感谢你! – Bagata 2013-09-06 00:55:15