Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Setting Content-Type when POSTing with LWP

by koscher (Initiate)
on Aug 29, 2002 at 21:10 UTC ( #193917=perlquestion: print w/replies, xml ) Need Help??

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

I'm using LWP to do a multi-part POST. In the body section associated with the file the header Content-Type header is set to Text/Plain.
How do I set it to something else (like Application/XML)?
example:

Content-Disposition: form-data; name="fname"; filename="deposit1.xml"
Content-Length: 1076
Content-Type: text/plain
<?xml version="1.0" encoding="utf-8"?>
  • Comment on Setting Content-Type when POSTing with LWP

Replies are listed 'Best First'.
Re: Setting Content-Type when POSTing with LWP
by Moonie (Friar) on Aug 29, 2002 at 21:51 UTC
    See lwpcookbook for reference. An example:
    my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/Bug +Glimpse'); $req->content_type('application/x-www-form-urlencoded'); $req->content('match=www&errors=0');
Re: Setting Content-Type when POSTing with LWP
by larryk (Friar) on Aug 29, 2002 at 21:59 UTC
    This is untested and I have to rush off but I hope it works
    #!perl use strict; use warnings; use LWP::UserAgent; use HTTP::Headers; use HTTP::Request; my $content = join '', <DATA>; my $ua = LWP::UserAgent->new(); my $h = HTTP::Headers->new( Content_Disposition => 'form-data; name="fname"; filename="deposit +1.xml"', Content_Length => length($content), Content_Type => 'text/xml' ); my $r = HTTP::Request->new('POST', 'http://search.cpan.org/', $h, $con +tent); my $response = $ua->request($r); __DATA__ <?xml version="1.0"?> ...
       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://193917]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-06-30 10:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (97 votes). Check out past polls.

    Notices?