【发布时间】:2013-11-10 15:03:06
【问题描述】:
我发现我的上传 perl 在我的 apache 上返回空文件,但使用 CURL 发布它可以正常工作:
@FILES = qw (o1.tmp o2.tmp o3.tmp);
foreach $filename (@FILES) {
$ua=LWP::UserAgent->new;
$proxy = "http://$USERNAME:$PASSWORD\@$PROXY_ADD";
$ua->proxy(['http', 'https'], $proxy);
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
my $url = "http://www.XXXXXXXXX.es/handler.php";
my $picture = $filename;
my %args;
my $field_name = "userfile";
my $buf ;
my $buf_ref = $args{'buf'} || \$buf ;
my $value = read_file( $picture , binmode => ':raw' , scalar_ref => 1 );
my $response = $ua->post( $url,
Content_Type => 'form-data',
Content => [ $field_name => ["$picture"] ]
);
print $response->content;
}
返回空文件:
root@dasdasd:/var/www/upload# ls -l
total 0
-rw-r--r-- 1 www-data www-data 0 oct 30 20:08 tmp_30-10-2013_0808pm_5554.tmp
-rw-r--r-- 1 www-data www-data 0 oct 30 20:08 tmp_30-10-2013_0808pm_8437.tmp
-rw-r--r-- 1 www-data www-data 0 oct 30 20:08 tmp_30-10-2013_0808pm_8629.tmp
但是有了这个 cURL 代码:
XXX-MacBook-Pro:Desktop xxxxxx$ curl -X PUT --header "Content-Type:multipart/form-data" --header "Name: 1" --data-binary "@2.gif" -v http://www.xxxxxxxxxx.es/handler.php
作品:
root@Arvaro:/var/www/upload# ls -l
total 4
-rw-r--r-- 1 www-data www-data 0 oct 30 20:08 tmp_30-10-2013_0808pm_5554.tmp
-rw-r--r-- 1 www-data www-data 0 oct 30 20:08 tmp_30-10-2013_0808pm_8437.tmp
-rw-r--r-- 1 www-data www-data 0 oct 30 20:08 tmp_30-10-2013_0808pm_8629.tmp
-rw-r--r-- 1 www-data www-data 6 oct 30 20:40 tmp_30-10-2013_0840pm_1978.tmp
^^^
not empty
任何人都可以在这里放一些光吗?
谢谢
【问题讨论】:
-
您将 PUT 与
curl一起使用,但将 POST 与 LWP 一起使用。您使用curl证明名称标头,但不使用 LWP。 -
你的代码LWP代码有很多死代码,包括
$ua->proxy(['http', 'https'], $proxy);。 -
响应的 HTTP 状态 ling 是什么?
-
$ua->proxy(['http', 'https'], $proxy);用于代理上的基本身份验证。我认为是需要的。关于其余的......当然......大量的死代码。我不知道响应的 HTTP 状态。我在脚本的输出上没有看到任何响应。关于放置/发布...我可以尝试在 LWP 中使用 PUT ..但我不知道正确的方法。如果您提出任何建议,我可以尝试一个代码(顺便说一句)。
-
如果需要
->proxy,那你就有问题了。您没有将它用于$ua用于post。