WWW::Mechanize 提交上的文件名不正确
据我所知,WWW::Mechanize 文档,您可以执行以下操作来从字符串提交文件:
$mech->submit_form(
fields => {
'UploadedFile' => [[ undef, 'test2.txt', Content => $content ], 1],
}
);
这应该提交一个带有名称的文件text2.txt
,包含 $content
中的文本(在本例中为'The file is a lie.'
)。
然而,请求因内部服务器错误而失败,所以我检查了发送的请求,发现了这一点:
--xYzZY
Content-Disposition: form-data; name="UploadedFile"; filename="ARRAY(0x9567570)"
The file is a lie.
--xYzZY
这显然不是我指定的文件名,所以我想知道:我做错了什么,还是模块有问题?
As far as I can read from the WWW::Mechanize documentation, you can do the following to submit a file from a string:
$mech->submit_form(
fields => {
'UploadedFile' => [[ undef, 'test2.txt', Content => $content ], 1],
}
);
This should submit a file with name text2.txt
, containing the text in $content
(in this case, 'The file is a lie.'
).
The request failed with an internal server error, however, so I examined the request that was sent, and found this:
--xYzZY
Content-Disposition: form-data; name="UploadedFile"; filename="ARRAY(0x9567570)"
The file is a lie.
--xYzZY
That is clearly not the filename I specified, so I wonder: Am I doing something wrong, or is the module bugged?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 HTML::Form 中的一个错误。我已经向作者反映了。
同时,如果您有 HTML::Form 版本 6.00,您可以通过注释掉 HTML/Form.pm 中的第 1442 行来临时修复问题,该行内容为
This is a bug in HTML::Form. I have reported it to the author.
In the mean time, if you have HTML::Form version 6.00, you can fix things temporarily by commenting out line 1442 in HTML/Form.pm which reads