Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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
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?

    Check
    LWP::UserAgent
    HTTP::Request::Common

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

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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-12-28 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls