Perl LWP :: UserAgent得不到答案

时间:2012-01-12 08:12:16

标签: perl lwp-useragent http-request

我正在向HTTP服务器发送POST请求而我没有回答。代码是

my $req = HTTP::Request->new(POST  => $url);
    $req->content_type('application/html');
    $req->content($text);
my $response = $browser->request($req);

应用程序挂起请求直到超时。 服务器,独立应用程序,正在发送答案,但我的脚本没有收到它。 服务器接收数据。 任何根本原因的想法?如果收到,丢弃等信息,如何获取更多细节。格式错误等?

已添加完整代码:

#!/usr/bin/perl -w
use strict;

use LWP;
use HTTP::Request::Common;

my $browser = LWP::UserAgent->new( );
$browser->env_proxy( ); # if we're behind a firewall

my $path =$ARGV[0]; #'file to send';
my $url = $ARGV[1]; #'http://127.0.0.1:9000';

open (MYFILE,  $path) or die "Can't open $path\n";
my $text = do { local $/; <MYFILE> };
close (MYFILE) or die "Can't close $path\n";; 


my $req = HTTP::Request->new(POST  => $url);
    $req->content_type('application/html');
    $req->content($text);

my $response = $browser->request($req);

if ($response->is_success) { print $response->content; }
else { print $response->message; };

0 个答案:

没有答案