Hi,
I think I may have issues with the encoding in the perl below. Trying to
monitor the http request/response using Fiddler I see some content length
warnings at times. I also think there may be an encoding problems because the
web server I am posting to seems to return an error.
I believe XML::Smart defaults to ASCII encoding or iso-8859-1 which I think are
the same thing. I wonder though if LWP is using UTF-8 by default, and maybe
that is causing me issues?
Thanks in advance for any input you can provide.
-angus
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request;
use XML::Smart;
my $doc = XML::Smart->new();
$doc->{header} {data} {struct} {var}[0] = {name => 'USERID'} ;
$doc->{header} {data} {struct} {var}[0] {string} = ‘john.doe';
$doc->{header} {data} {struct} {var}[0] {string}->set_node(1);
$doc->{header} {data} {struct} {var}[1] = {name => 'USERPASSWORD'};
$doc->{header} {data} {struct} {var}[1] {string} = ‘FAKEPASSWORD';
$doc->{header} {data} {struct} {var}[1] {string}->set_node(1);
$doc->{header} {data} {struct} {var}[2] = {name => 'PARTNERID'};
$doc->{header} {data} {struct} {var}[2] {string} = ‘1';
$doc->{header} {data} {struct} {var}[2] {string}->set_node(1);
$doc->save('passport.xml');
my $sendXML="passport.xml";
my $resultXML="passport_result.xml";
my $webpage="https://example.com/login/autologin_xml.asp";
my $message="";
open (XML,$sendXML);
while (<XML>) {
$message .="$_";
}
close XML;
my $ua = LWP::UserAgent->new;
print "what we sent\n";
$ua->add_handler("request_send", sub { shift->dump; return });
print "what we got back\n";
$ua->add_handler("response_done", sub { shift->dump; return });
$ua->proxy('https', 'http://proxy.example.net:8080/');
my $response = $ua->post($webpage, Content_Type => 'text/xml', Content =>
$message);
#my $response = $ua->request(POST "$webpage", Content_Type => 'text/xml',
Content => $message);
if ($response->is_success) {
# print $response->decoded_content; # or whatever
}
else {
die print $response->status_line;