I am trying to post some xml to a web service but when I do this my browser returns and error about the format of my xml. However, if I try this from a command line I get what I expect in return. I think the issue might be related to the format of the data I am trying to post. I thought I might resolve this issue by trying to encode the message using uri_escape from the URI::Escape module but that did not appear to resolve the issue. Here is a sample of my code so far.

#!/usr/bin/perl use warnings; use strict; use XML::Smart; use LWP::UserAgent; my $doc = XML::Smart->new(); $doc->{PHC_LOGIN}{USERID} = 'john.doe'; $doc->{PHC_LOGIN}{USERID}->set_node(1); $doc->{PHC_LOGIN}{USERPASSWORD} = 'FAKEPASSWORD'; $doc->{PHC_LOGIN}{USERPASSWORD}->set_node(1); $doc->{PHC_LOGIN}{PARTNERID} = '111'; $doc->{PHC_LOGIN}{PARTNERID}->set_node(1); $doc->save('output.xml'); my $sendXML="output.xml"; my $webpage="https://example.com/Login/AutoLogin.aspx"; my $message=""; open (XML,$sendXML); while (<XML>) { $message .="$_"; } close XML; my $ua = LWP::UserAgent->new; $ua->add_handler("request_send", sub { shift->dump; return }); $ua->add_handler("response_done", sub { shift->dump; return }); $ua->proxy('https', 'http://proxy.example.net:8080/'); my $header= $ua->default_headers; my $response = $ua->post($webpage, Content_Type => 'text/xml', Content + => $message); $response->decoded_content; if ($response->is_success) { my $html = $response->content; if ( $html =~ /\<REDIRECTURL\>(.*)\<\/REDIRECTURL\>/) { my $dest = $1; $ua->post($dest); } else { print "No redirect url found\n"; }; } else { die print $response->status_line; print $response->decoded_content; };

In reply to http url encoding issues. by argos

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.