Re: PATCH: Using "plain" content for ->post method

Gisle Aas <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
Slaven Rezic <[email protected]> writes:

> The attached patch adds the feature to use plain content (that is, no
> param-value pairs) for POST requests.

Since POST() already support plain content I instead applied the
following patch that tries to document this better and makes
$ua->post() not block this feature.  Your test suite addition was
applied with a little tweak. Thanks!

If you apply this patch to LWP::UserAgent you should be able to do
what you want with:

    my $res = $ua->post($soap_url,
        Content_Type => "text/xml;charset=UTF-8",
        SOAPAction   => "Something",
        Content      => $soap_request_string,
    );

Regards,
Gisle



--- lib/HTTP/Request/Common.pm	15 Nov 2004 14:52:37 -0000	1.26
+++ lib/HTTP/Request/Common.pm	14 Dec 2005 21:01:07 -0000
@@ -343,6 +343,12 @@ $ua->request(HEAD ...).
 
 Like GET() but the method in the request is "PUT".
 
+The content of the request can be specified using the "Content"
+pseudo-header.  This steals a bit of the header field namespace as
+there is no way to directly specify a header that is actually called
+"Content".  If you really need this you must update the request
+returned in a separate statement.
+
 =item POST $url
 
 =item POST $url, Header => Value,...
@@ -351,10 +357,16 @@ Like GET() but the method in the request
 
 =item POST $url, Header => Value,..., Content => $form_ref
 
-This works mostly like GET() with "POST" as the method, but this function
-also takes a second optional array or hash reference parameter
-($form_ref).  This argument can be used to pass key/value pairs for
-the form content.  By default we will initialize a request using the
+=item POST $url, Header => Value,..., Content => $content
+
+This works mostly like PUT() with "POST" as the method, but this
+function also takes a second optional array or hash reference
+parameter $form_ref.  As for PUT() the content can also be specified
+directly using the "Content" pseudo-header, and you may also provide
+the $form_ref this way.
+
+The $form_ref argument can be used to pass key/value pairs for the
+form content.  By default we will initialize a request using the
 C<application/x-www-form-urlencoded> content type.  This means that
 you can emulate a HTML E<lt>form> POSTing like this:
 
--- lib/LWP/UserAgent.pm	16 Sep 2004 09:28:22 -0000	2.33
+++ lib/LWP/UserAgent.pm	14 Dec 2005 21:01:08 -0000
@@ -423,7 +423,7 @@ sub get {
 sub post {
     require HTTP::Request::Common;
     my($self, @parameters) = @_;
-    my @suff = $self->_process_colonic_headers(\@parameters,2);
+    my @suff = $self->_process_colonic_headers(\@parameters, (ref($parameters[1]) ? 2 : 1));
     return $self->request( HTTP::Request::Common::POST( @parameters ), @suff );
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.