如何将来自 Perl 的多部分 HTTP 请求 POST 到 Java 并获得响应?
我正在尝试从 Perl 中的一个子例程向基于 Java 的控制器发出请求。 但我没有得到任何回复。我知道 Java 代码工作文件,因为如果我从 HTML 表单发布到它,我可以获得响应。
这是我的 Perl 代码:
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
my $response = $ua->request(POST 'http://testserver/testing.nc',
Content_Type => 'form-data',
Content => [
method => 'submit',
ftp_server => 'ftp.localhost',
ftp_user => 'testuser',
ftp_password => 'testpass',
remote_path => '/home/files',
port => 22,
file_to_upload => ["$file"]
]);
这段代码有问题吗?
I'm trying to post from one of my subroutines in Perl a request to a Java based controller.
But I'm not getting any kind of response back. I know the Java code works file because I can get a response if I post to it from a HTML form.
This is my Perl code:
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
my $response = $ua->request(POST 'http://testserver/testing.nc',
Content_Type => 'form-data',
Content => [
method => 'submit',
ftp_server => 'ftp.localhost',
ftp_user => 'testuser',
ftp_password => 'testpass',
remote_path => '/home/files',
port => 22,
file_to_upload => ["$file"]
]);
Is there something wrong with this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布的数据必须为
multipart/form-类型数据
。编辑:好的,事实证明,指定
form-data
就足够了,正如HTTP::Request::Common 文档:但是,要按照您使用的方式使用
HTTP::Request::Common::POST
,您需要导入POST
:或使用
$ua-> ;帖子:
使用 WWW::Mechanize 可以使您的生活更轻松。另请参阅此上传示例。
Posted data must be of type
multipart/form-data
.Edit: OK, so it turns out, specifying
form-data
is enough as mentioned in the HTTP::Request::Common docs:However, to use
HTTP::Request::Common::POST
the way you are using, you will need to importPOST
:or use
$ua->post
:You can make your life easier by using WWW::Mechanize. See also this upload example.