This is a guess but I've added an explicit HTTP::Headers object, set the content-type and included your XML content directly in the HTTP::Request constructor. I used something I previously worked on as a reference. I hope this helps.
require HTTP::Headers;
my $header = HTTP::Headers->new();
$header->header( 'Content-Type' => 'text/xml' );
require HTTP::Request;
my $postRequestObject = HTTP::Request->new(
POST => $POST_URL,
$header,
[ CLRCMRC_XML => $finalXML ] );
| [reply] [d/l] |
How do you want to POST the XML? Do you want to do a normal
form POST or use multipart/form-data? The "key=value" format is used by the standard urlencoded format. In that case, you would need to encode the value. Be aware that most web servers aren't going to like receiving huge values with that kind of POST. Luckily, HTTP::Request will construct form-data requests for you if you give it the right arguments.
$postRequest = HTTP::Request('POST' => $POST_URL,
Content_Type => 'form-data',
Content => [ CLRCMRC_XML => $finalXML ]);
| [reply] [d/l] |
Okay, thank you both! However, neither suggestion did what I need it to do. I've figured out that the server is not going to unencode anything so the XML needs to be sent in plain text, no encoding. This works:
my $finalXML = $self->getFinalXML();
my $POST_URL = $self->getProcessingURL();
print $finalXML, "\n";
use Net::SSLeay;
my ($page, $response, %reply_headers) =
Net::SSLeay::post_https(
'dev.xmlsite.com',
11800,
'',
Net::SSLeay::make_headers('Content-Type' => 'text/xml'),
"CLRCMRC_XML=$finalXML"
);
foreach my $key (keys %reply_headers) {
print "$key: ", $reply_headers{$key}, "\n";
}
print 'Response: ', $response, "\n";
print 'Page: ', $page, "\n";
...and it's nice because I've got my XML response in a separate variable out of gate: $page. I'd like to do the above using LWP, but I can't figure out how to send content unencoded, ie. plain text. I'm stumped.
dpatrick - I think scsh is cool.
Open Sourceror, Perlmonk
http://perlmonk.org/~dpatrick
| [reply] [d/l] |
That's incomprehensible. XML is always encoded whether using Latin1, UTF-8, KOI-5 or whatever. Probably the most "plain text" version you'll see is Latin1. That doesn't mean the XML doesn't need to be encoded properly. XML is always encoded. Perhaps you meant that the server accepts XML-like data but that it's not really XML? That'd be the case if you mean to pass in things like this:
<r>
<k> 10 < 20 </k>
</r>
vs
<?xml encoding="ISO-8859-1" version="1.0?>
<r>
<k> 10 < 20 </k>
</r>
In all encodings of XML I'm aware of you are required to rewrite "<" as something like "<" / "<" / "<". Or have you thrown me a loop here on the encoding business?
__SIG__
printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::
+svref_2object(sub{})->OUTSIDE
| [reply] [d/l] |
Hi-
What you are trying to do is less than totally clear from the question you asked, but I think the solution you found and posted subsequently cleared it up somewhat. From my point of view there are only two possibilities of what you are trying to do:
- POST some XML as a parameter of a form, e.g. some XML that was pasted or typed in a HTML <input type="text"> or <textarea> widget.
- POST some XML as the body of a HTTP request, with a Content-type header of text/xml (or whatever). This is a perfectly legitimate thing to want to do, particularly if you are building a RESTful web service.
It seems pretty clear from your answer that what you're talking about is no. 2. Care to comment?
While this is an aside (because you got the POST over HTTPS to work and that's probably all that matters to you), I feel compelled to point out that what you're posting isn't XML, it appears to be a string "CLRCMRC_XML=$finalXML", for whatever value of $finalXML. This makes the semantics of the HTTP request quite unclear; the Content-type header is blatantly misleading (or even just 'wrong').
You mightn't give a rat's ass about this because the semantics are in your brain; nonetheless I think I would just give that a mime type of plain text or something in the Content-type header. | [reply] |
Check my response to diotalevi above.
It actually turns out that it is a combination of 1 and 2, as you'll see from the above response. They're doing things in a strange way (the folks who are accepting the XML), I'm guessing possibly so that they can accept other data in other form variables, but this other data could just as easily be added into one XML document...I don't know. Anyway, yes you are right, the Content-type was incorrect, but it was not being parsed on the accepting end anyway. You are also right again in that I'm not posting XML. I'm posting a form, without the proper content-type (which I could, in fact, send anyway if I wanted to because they're not parsing it anyway), with valid XML data in one of the form fields as a string.
It's weird. But Perl Monks rock!
dpatrick - I think scsh is cool.
Open Sourceror, Perlmonk
http://perlmonk.org/~dpatrick
| [reply] |