gjwilson21 has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am currently working on automating file submission to a portal. I face a problem regarding content types. My request is like

$filename='testfile'; $req=POST 'https://www.abcd.com/fileUpload.aspx', Content_Type=>'form- +data', Content => [file1=>["$filename"],file4=>[""],file5=>[""]];
I expect a request something like
--xYzZY Content-Disposition: form-data; name="file1"; filename="testfile " Content-Type: application/octet-stream Test File Contents --xYzZY Content-Disposition: form-data; name="file4" filename="" --xYzZY Content-Disposition: form-data; name="file5" filename=""
since the data i captured using a HTTP Sniffer showed the request was like this. But the request it is generating is like
--xYzZY Content-Disposition: form-data; name="file1"; filename="testfile " Content-Type: application/octet-stream Test File Contents --xYzZY Content-Disposition: form-data; name="file4" --xYzZY Content-Disposition: form-data; name="file5"
Please help me figure out how to create a request like this. Thanks in advance

Replies are listed 'Best First'.
Re: Query regarding HTTP:Request
by atemon (Chaplain) on Jul 26, 2007 at 08:22 UTC

    Hi,

    Please refer to HTTP::Request::Common. When you have files, you need to give the absolute path. so you may write like

    $filename="$ENV{HOME}/testfile"; # File name with absolute path $req=POST 'https://www.abcd.com/fileUpload.aspx', Content_Type=>'form- +data', Content => [file1=>["$filename"],file4=>[""],file5=>[""]];
    The post(...) method of "LWP::UserAgent" exists as a shortcut for $ua->request(POST ...).

    Note: Code is NOT tested

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

Re: Query regarding HTTP:Request
by Anonymous Monk on Jul 26, 2007 at 07:09 UTC