1

此脚本 AUTH 成功,但无法正确返回网页,服务器返回。

HTTP/1.1 100 Continue HTTP/1.1 303 See Other Date: Thu, 18 Oct 2012
20:36:45 GMT Server:    Apache/2.2.14 (Ubuntu) X-Powered-By:
PHP/5.2.6-3ubuntu4.6 Set-Cookie:
MoodleSessionmain=9b04143933c4ae2564e5be247fc8463d; path=/ Expires:
Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache,
must-revalidate, post-check=0, pre-check=0 Pragma: no-cache
Set-Cookie: MoodleSessionTestmain=Qf2kfwifF3; path=/ Set-Cookie:
MOODLEID_main=deleted; expires=Wed, 19-Oct-2011 20:36:44 GMT; path=/
Set-Cookie: MOODLEID_main=%25E2%25C2%2519C%25BDg%25B1%2502%25E5%255D;
expires=Mon, 17-Dec-2012 20:36:45 GMT; path=/ Location:
http://main.ingeniat.com/my/index.php Vary: Accept-Encoding
Content-Length: 202 Connection: close Content-Type: text/html
Set-Cookie: SERVERID=guia5; path=/ HTTP/1.1 200 OK Date: Thu, 18 Oct
2012 20:36:45 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By:
PHP/5.2.6-3ubuntu4.6 Expires: Cache-Control: private, pre-check=0,
post-check=0, max-age=0 Pragma: no-cache Content-Script-Type:
text/javascript Content-Style-Type: text/css Content-Language: es
Accept-Ranges: none Vary: Accept-Encoding Connection: close
Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8

这是代码

$post_fields = array();
$post_fields['username']=$usr;
$post_fields['password']=$pass;

$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields );


curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");

echo curl_exec($ch);
curl_close($ch);

我究竟做错了什么?

4

2 回答 2

1

CURLOPT_HEADER 没有提到任何关于排除正文的内容。 http://php.net/manual/en/function.curl-setopt.php

但也许您的页面重定向超过 10 次?也许添加

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

然后发布您的新标题。

于 2012-10-18T20:58:14.643 回答