【问题标题】:Error POSTing File in Perl在 Perl 中发布文件时出错
【发布时间】:2014-08-16 16:47:53
【问题描述】:

我正在尝试重建一个请求(文件上传),来自网络浏览器的打包发送如下所示:

-----------------------------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'
    ]);

遗憾的是,这给了我“内部服务器错误”错误... 我做错了什么?

【问题讨论】:

    标签: forms perl post request


    【解决方案1】:

    根据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'
        ]
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-02
      • 2015-11-14
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      相关资源
      最近更新 更多