我试图重建一个请求(文件上传),来自webbrowser的打包发送如下所示:
-----------------------------596088922920
Content-Disposition: form-data; name="Filedata"; filename="mypic.gif"
Content-Type: image/gif
GIF87aX# *shorted* ¡§\
-----------------------------596088922920
Content-Disposition: form-data; name="session"
92384729384792384729384729384
-----------------------------596088922920
Content-Disposition: form-data; name="method"
put
-----------------------------596088922920--
我的每个代码看起来像这样:
use WWW::Mechanize;
$agent = WWW::Mechanize->new( cookie_jar => {} );
$agent->post('http://www.kleiderkreisel.de/photo/ajax_photo_action',
[
"Filedata" => ['mypic.gif' => 'C:\Pics\mypic.gif'],
'session' => '92384729384792384729384729384',
'method' => 'put'
]);
遗憾的是,这给了我错误“内部服务器错误”... 我做错了什么?
答案 0 :(得分:4)
根据HTTP::Request::Common
(从LWP::UserAgent->post
引用的WWW::Mechanize->post
引用)的文档,您必须明确将内容类型设置为form-data
。因此代码应该是:
$agent->post('http://www.kleiderkreisel.de/photo/ajax_photo_action',
Content_Type => 'form-data',
Content => [
"Filedata" => ['mypic.gif' => 'C:\Pics\mypic.gif'],
'session' => '92384729384792384729384729384',
'method' => 'put'
]
);