curl 模拟登陆成功以后,访问页面返回500错误。

liupandeng1984 2011-05-15 01:31:35
<?php
header("Content-type: text/html; charset=utf-8");

require_once('yanzheng.php');
require_once('include/function.php');

// 登录系统
$url = "http://";
$post = array(
'Id' => '888',
'username' => 8888',
'password' => '8888', //密码
'captcha' => $_POST["yzm"],); //验证码

$login = curl_open($url,array('post'=>$post));
if (!strpos($login,"管理系统")) exit("登录失败");



//访问,不需要post参数,不登录访问这个网址,会返回302,跳转到登录页面。
$url = "http://";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) .'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) .'/cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

返回
HTTP/1.1 500 Internal Server Error
Date: Sun, 15 May 2011 05:15:45 GMT
Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8o mod_jk/1.2.30
Cache-Control: max-age=0
Expires: Sun, 15 May 2011 05:15:45 GMT
Vary: Accept-Encoding
Content-Length: 2696
Connection: close
Content-Type: text/html;charset=UTF-8

//其中的函数
function curl_open($url, $conf = array())
{
if(!function_exists('curl_init') or !is_array($conf)) return FALSE;

$post = '';
$purl = parse_url($url);

$arr = array(
'post' => FALSE,
'return' => TRUE,
'cookie' => dirname(dirname(__FILE__)) .'/cookie.txt',);
$arr = array_merge($arr, $conf);
$ch = curl_init();

if($purl['scheme'] == 'https')
{
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $arr['return']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $arr['cookie']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $arr['cookie']);

if($arr['post'] != FALSE)
{
curl_setopt($ch, CURL_POST, TRUE);
if(is_array($arr['post']))
{
$post = http_build_query($arr['post']);
} else {
$post = $arr['post'];
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}

$result = curl_exec($ch);
curl_close($ch);

return $result;
}

返回页面有个提示:java.lang.NullPointerException

求大家帮帮忙啊,很急。
...全文
875 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
哈哈哈3234 2011-05-17
  • 打赏
  • 举报
回复
不明白,lz加油!

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧