Question

I'm trying to use LWP to post some content to a hosted service, over which I have no control, i.e. I must conform to their standards.

Basically, the content must go over in a post which looks similar to the following:

POST / HTTP/1.1
Accept:*/*
Content-Type: text/xml
[various other headers]

<?xml version="1.0" encoding="UTF-8"?>
<xmlContent>here</xmlContent>

I'm looking at the LWP documentation, and its example looks like this:

$response = $browser->post( $url,
   ['form' => '<?xml version="1.0" encoding="UTF-8"?><content>foobarbaz</content>'],
   'Content_Type' => 'text/xml', 
   'headerkey2' => 'hvalue2', 
 );

so instead, my data is going over like this:

[headers]

form=<?xml blah blah blah

I don't want the "form=" in there.

I've tried a few work-arounds, but I either end up with nothing getting sent, or with an extra '=' sign at the end. It seems like this should be easy... is there any way I can get my content to go as the body of the post WITHOUT the variable name?

I'm open to doing things other than using LWP, that was just my jumping off point because I've used it before.

Thanks!

Was it helpful?

Solution

I don't think you need a FORM:

  $req = HTTP::Request->new(POST => $url);
  $req->header("Content-Type" => "text/xml");
  $req->content(<<EOT);
  <?xml version="1.0" encoding="UTF-8"?>
  <xmlContent>here</xmlContent>
  EOT
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top