Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

POST request issue

by AnarchyNZ (Initiate)
on Oct 07, 2013 at 03:56 UTC ( #1057215=perlquestion: print w/ replies, xml ) Need Help??
AnarchyNZ has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to do a post request to a website where instead of uploading a file you post text which mimics a file.

I have been told that I can send something like this in the body

Content-Disposition: form-data; name=”fileBody”; filename=”[Placeholder file name]”;
Content-Type: text/plain

[File Text]

But I have not been able to find how to do it in Perl.

Any help would be greatly appreciated

Comment on POST request issue
Replies are listed 'Best First'.
Re: POST request issue
by moritz (Cardinal) on Oct 07, 2013 at 08:38 UTC

    Most Perl user agent modules allow you to create POST request with arbitrary body content, and of course you can also set headers the way you want. So you could write, for example:

    use LWP::UserAgent; use HTTP::Headers; my $headers = HTTP::Headers->new(); $headers->header('Content-Disposition', 'form-data; name="fileBody"; f +ilename="[Placeholder file name]"); $headers->header('Content-Type', 'text/plain'); my $ua = LWP::UserAgent->new( default_headers => $headers, ); my $response = $ua->post($URL, Content => $content_of_your_file);

    I hope that helps. If not, please reformulate your question.

Re: POST request issue
by exilepanda (Monk) on Oct 07, 2013 at 07:05 UTC
    I am a bit confused about your question. Do you want to make a post request ? or you want to upload a text file?


    However, you should only consider what the server expects, but not what you like to send.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057215]
Approved by Tanktalus
Front-paged by Tanktalus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2015-11-29 20:10 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (753 votes), past polls