免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1826 | 回复: 3
打印 上一主题 下一主题

一个超级简单的lwp问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-01 13:58 |只看该作者 |倒序浏览
我作了一个测试文件 test.php
<?php
    if($_POST['submit'])
    {
        $user = trim($_POST['username']);
        if(!empty($user))
        {
                echo "Right!";
                exit;

        }else{
                echo "Wrong";
                exit;
        }
    }


?>



<html>
<title>test </title>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
<body>
<center>
<form method=POST action=/test.php>
<table>
<tr>
    <td>姓名:</td><td><input type=text name=username></td>
</tr>
</table>
<input type=submit name=submit value=" 提交  ">
</form>
</center>
</body>
</html>


之后在本机用写了一个perl文件(test.pl),模拟提交的,代码如下:

#!/usr/bin/perl

use strict;
use LWP;
use URI::Escape;
use HTTP::Request::Common;

use constant RFC_SEARCH  => 'http://10.3.1.107/test.php';
use constant RFC_REFERER => 'http://10.3.1.107/test.php';
my $ua       = LWP::UserAgent->new;
my $search_terms = "@ARGV";
my $request = POST ( RFC_SEARCH,
                     Content => [ username   => $search_terms ],
                     Referer => RFC_REFERER
                   );

my $response = $ua->request($request);
die $response->message unless $response->is_success;
my $content = $response->content;
print $content;


我运行 test.pl ddd
问题是,打印出来的$content之后,既不是Right,也不是Wrong,而是HTML源代码。请问什么原因???
十分感谢~~

论坛徽章:
0
2 [报告]
发表于 2007-02-01 16:36 |只看该作者

回复 1楼 lvlfforever 的帖子

simplest way to set your php script httpd header as "content-type: text/plain"
after $_POST['submit'] was checked.
for eaxample:
<?php
if ($_POST['submit']) {
    header("content-type: text/plain");
    ....
}
?>


PHP as default outputs usually "content-type: text/html" with some html z´tag.

-- ulmer

论坛徽章:
0
3 [报告]
发表于 2007-02-01 16:56 |只看该作者
use constant RFC_SEARCH  => 'http://10.3.1.107/test.php?submit=1';

or
my $request = POST ( RFC_SEARCH,
                     Content => [ username   => $search_terms ,submit => 1],
                     Referer => RFC_REFERER
                   );

论坛徽章:
0
4 [报告]
发表于 2007-02-02 11:38 |只看该作者
多谢二位,光明使者的方法解决了问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP