Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

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 (Pilgrim) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-04-25 21:25 GMT
Find Nodes?
    Voting Booth?