curl认证,但不返回网页 [英] curl authenticates but no web page is returned
本文介绍了curl认证,但不返回网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTTP / 1.1 100继续HTTP / 1.1 303查看其他日期:Thu,2012年10月18日
20:36:45 GMT服务器: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,
必须重新验证,post-check = 0,pre-check = 0 Pragma:no-cache
Set-Cookie:MoodleSessionTestmain = Qf2kfwifF3; path = / Set-Cookie:
MOODLEID_main = deleted; expires = Wed,2011年10月19日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服务器: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-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);
我做错了什么?
解决方案
CURLOPT_HEADER没有提到排除身体的任何事情。
http://php.net/manual/en/function.curl -setopt.php
但也许您的网页重定向超过10次?也许添加
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,1);
,然后发布新标题。
This script AUTHs successfully but it wont return the webpage correctly, the server returns.
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
Here's the code
$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);
What am I doing wrong?
解决方案
CURLOPT_HEADER doesn't mention anything about excluding the body. http://php.net/manual/en/function.curl-setopt.php
But maybe your page is redirecting more than 10 times? Maybe add
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
and then post your new headers.
这篇关于curl认证,但不返回网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文