I have a web service i am submitting an xml file (using nettool currently to submit it). Having a hard time sending the request via perl HTTP. I am thinking that i might need to serialize the xml file, then send it over however a bit amiss at how to accomplish this. This is what i have so far, and based this on a simple POST script that does work. The nettool request using the url in the script and the contents of the test.xml file works perfect and i get a 200 response with data. I keep getting 400 bad request here...
#!/usr/bin/perl -w use strict; use FileHandle; use LWP::UserAgent; use HTTP::Request; sub printFile($) { my $fileHandle = $_[0]; while (<$fileHandle>) { my $line = $_; chomp($line); print "$line\n"; } } my $fh = new FileHandle; $fh->open("</home/test.xml") or die "Could not open file\n"; printFile($fh); $fh->close(); # automatically closes file; my $userAgent = LWP::UserAgent->new(); my $request = HTTP::Request->new(POST => 'http://test.com:7080/b2b?msg +Fmt=testRequest'); $request->header('Host' => "test.com:7080"); $request->content($fh); $request->content_type("text/xml; charset=utf-8"); my $response = $userAgent->request($request); if($response->code == 200) { print $response->as_string; } else { print $response->error_as_HTML; } #

In reply to Sending xml message in perl by mikes300

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.