"Ed Bras" <[EMAIL PROTECTED]> writes:

> I have beeing playing the last few day with the libwww modules and 
> have some questions about it:
>  
> 1: The first question has a lot to with question 2, but here it goes. How can I 
>simulate a file upload when I have the file content already stored in a variable , by 
>using HTTP::Request::Common POST ?

    POST $url,
         content_type => 'form-data',
         content => [
            foo  => bar,
            file => [undef, "filename", Content_type => 'text/plain', Content => 
$variable],
        ];

> 2: How to use the "boundarry" correctly ?

You should generally just let &POST generate it for you.

> I try to change it such that it doesn't start a new field after a ^M when the 
>content of a file is directly stored into a variable and uploaded through a regular 
>field.
> I changed the Content_Type entry in the below text, but without any luck
> 
> First I had
> 
> my $req = POST 'http://ojo/~ed/uploadtest.cgi',
> >>
> my $req = POST 'http://ojo/~ed/uploadtest.cgi',
> Content_Type => "form-data",
> Content => [
> snorkel => `cat $ENV{HOME}/.bashrc`

The `cat ...` is here evaluated in list context and will return
separate lines as separate values.  &POST then tries to interpret them
as key/value pairs.  That will not look good.

> ]
> >>
>  
> which output looks something like this:
>  
> >>>
> --xYzZY^M
> Content-Disposition: form-data; name="snorkel"^M
> ^M
> export INPUTRC=~/.inputrc
> ^M
> --xYzZY^M
> Content-Disposition: form-data; name="export CVS_SERVER
> =/usr/bin/cvs
> "^M
> ^M
> alias ll='ls -al'
> ^M
> --xYzZY^M
> Content-Disposition: form-data; name="stty erase '^?'
> "^M
> ^M
> >>>
>  
>  
> I then changed it to
> 
> >>
> Content_Type => "form-data; boundary=20340712617089"

This disabled the 'form-data' special treatment of content.

> >>
>  
> But then the output looks like:
>  
> >>>
> POST http://ojo/~ed/uploadtest.cgi
> Content-Length: 166
> Content-Type: form-data; boundary=20340712617089'
> snorkel=export%20INPUTRC%3D~%2F.inputrc%0A&export%20CVS
> _SERVER%3D%2Fusr%2Fbin%2Fcvs%0A=alias%20ll%3D'ls%20-al'
> %0A&stty%20erase%20'%5E%3F'%0A=%23umask%20077%20%0A&%0A
> =
> >>>

Regards,
Gisle

Reply via email to