Chinaunix

标题: perl lwp提交表单的奇怪问题(is_success为空),跪求大虾解答 [打印本页]

作者: laijiren2008    时间: 2009-04-24 15:51
标题: perl lwp提交表单的奇怪问题(is_success为空),跪求大虾解答
我的php代码为reg.php
<?php
session_start();
require ('dbconnect.php');
?>
<?
$name=$_POST['name'];
$address=$_POST['address'];
$tel=$_POST['tel'];
$choice=$_POST['choice'];
$book=$_POST['book'];
$massage=$_POST['massage'];
$choice= $choice[1].$choice[2].$choice[3];
$ip=getenv (REMOTE_ADDR);
$now = date("Y-m-d H:i:s");
$sql="insert into book_1 (name,address,tel,choice,book,time,ip,massage) values ('$name','$address','$tel', '$choice', '$book', '$now', '$ip','$massage')";
mysql_query($sql,$conn) or die ("插入数据失败: ".mysql_error());
$id=mysql_insert_id();

mysql_close($conn);
session_register("username");
//$username=$id;
//echo $username;
//echo $_SESSION['username'];
$_SESSION['username']=$id;

header("Location:regok.php?id=$id");
?>

我的perl代码为book.perl#!/usr/bin/perl
use LWP;
use HTTP::Cookies;
use HTTP::Response;
use strict;
use warnings;
sub main{
my  $browser = LWP::UserAgent->new;
my  $response = $browser->post(
"http://10.71.98.46/book/reg.php",
[
"name"=>"laijiren",
"address"=>"aaaaaaa",
"tel"=>"cccc",
"book"=>"cccc",
"choice"=>"aaaabc",
"massage"=>"qewrt",
Referer=>'http://10.71.98.46/book/reg_input.php'

]
);
my $success=$response->is_success();
print "$success\n";
my $content=$response->content;
print "$content";

#$response->is_success() or die "FAILDED:", $response->status_line(), "$!\n";
#my $content=$response->content();
#print "$content\n";  

}
&main;

发现表单提交成功,但$response->is_success里确什么都没有,response->content里也什么都没有
这是什么问题
作者: hfahe    时间: 2009-04-24 16:20
header("Location:regok.php?id=$id"); 你最后跳转了?
作者: hfahe    时间: 2009-04-24 16:29
$response->is_success应该是1
$response->content应该是reg.php的输出
作者: laijiren2008    时间: 2009-04-24 16:31
但是我最后is_success里和content里确实空的
作者: laijiren2008    时间: 2009-04-24 16:33
是header的影响吗,跳转以后会影响结果?
作者: hfahe    时间: 2009-04-24 16:38
应该不影响 呵呵 不过可以注释掉试试
按照你的说法 php页面请求成功了 数据库插入了数据 但是is_success是false?

[ 本帖最后由 hfahe 于 2009-4-24 16:39 编辑 ]
作者: laijiren2008    时间: 2009-04-24 16:45
不是false,用print什么也打不出来,用defined($response->is_success)是1
作者: laijiren2008    时间: 2009-04-24 18:48
还是不行啊




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2