0

I have a program in which we are using LWP::UserAgent. We also have content defined as follows:

content => "columns[]=id&columns[]=..."

To invoke this POST method, I need to also send in a parameter

<request>getThisInfo</request>

How can I achieve this? Where should I set this request information? AFAIK, this can't be in the header.

This is what it looks like in SOAP UI.

enter image description here

Borodin
  • 126,100
  • 9
  • 70
  • 144
sahisahil
  • 13
  • 4
  • What does this have to do with XML? Do you have a description of the API you are talking to? – simbabque Feb 10 '17 at 10:16
  • the parameter is in xml format. Its a REST API. – sahisahil Feb 10 '17 at 10:17
  • Can I use header somehow to add this request parameter ? – sahisahil Feb 10 '17 at 10:25
  • To answer, we're going to need some more detail. But for an example of how to POST some XML, this might be of use: http://stackoverflow.com/questions/29009370/assembling-xml-in-perl – Sobrique Feb 10 '17 at 11:15
  • Please see the picture I added., it shows how its supposed to work using SOAP UI. I want to achieve same using Perl. – sahisahil Feb 10 '17 at 11:39
  • The `$ua->post( $url, { 'param' => 'value'} );` doesn't works for you? – clt60 Feb 10 '17 at 12:07
  • Thanks for answering, but No, it gives error "content is not allowed in prolog".. – sahisahil Feb 10 '17 at 12:22
  • Oh, I see. That should be fairly simple. It's just the body of the request. Since it's not complex XML you can just put it as a verbatim string. But the media type in your screenshot is `x/www-form-urlencoded`. Are you sure that's correct? The body is **not** URL encoded. And the content you were talking about is not there in the screenshot. – simbabque Feb 10 '17 at 12:54

1 Answers1

0

In your screenshot this XML-like string is in the body of the request. Just put it there the same way you showed your params.

use strict;
use warnings;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
my $res = $ua->post( $url, content => '<request>getThisInfo</request>');

You might need to set a different Content-Type header for the request. Also, now your query-params that you showed to be in the body are gone. But in your screenshot they are not there either. You need to decide what you want, and refer to the API documentation or ask the people providing the API.

simbabque
  • 53,749
  • 8
  • 73
  • 136