Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strip header from response LWP 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I'm tryig to parse a SOAP response, but using XML::Simple I am getting 'not well formed' error.

If i 'die' the returned data from the call I get..
Code:
HTTP/1.1 200 OK
Cache-Control: private
Date: Thu, 04 Oct 2007 09:48:16 GMT
Server: Microsoft-IIS/6.0
Content-Length: 496
Content-Type: text/xml
Client-Date: Thu, 04 Oct 2007 09:48:29 GMT
Client-Peer: 83.138.164.244:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/ST=UT/L=Salt Lake City/O=The USERTRUST Network/OU=[URL unfurl="true"]http://www.usertrust.com/CN=UTN-USERFirst-Hardware[/URL]
Client-SSL-Cipher: RC4-MD5
Client-SSL-Warning: Peer certificate not verified
Set-Cookie: dsfsdf; path=/
X-Powered-By: ASP.NET

<soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL]    soap:encodingStyle="[URL unfurl="true"]http://www.w3.org/2001/12/soap-encoding">[/URL]  

  <soap:Header/>  

  <soap:Body xmlns:res="[URL unfurl="true"]http://myurl">[/URL]  

    <object>  

      <Name></Name>

      <Description></Description>

      <Catagory></Catagory>

      <Source></Source>

      [b]<url>/test/key</url>[/b]

    </object>  

  </soap:Body>  

</soap:Envelope>

So you can see there is all that header data prior to the SOAP:envelope , how do I either access just the SOAP XML with LWP or what would be the best way to parse it?

could I use a regex and remove everything upto the first <soap:

or is there a parser module for this?

I'm trying to get the value of the <url> data.

all help appreciated.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
well I solved it like this...
Code:
my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => '[URL unfurl="true"]https://myurl/myapp.asp');[/URL]
$request->header(SOAPAction => 'mymethod');
$request->content($xml);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);

if($response->code == 200) {
    my $ret = $response->as_string;
    $ret =~ s/HTTP[^>]*<soap/<soap/i;
    use XML::Simple;
    my $ref = XMLin($ret);
    print "Location: [URL unfurl="true"]https://myurl"[/URL] . $ref->{'soap:Body'}->{'object'}->{'url'} . "\n\n";
}

Any thoughts?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
doesn't LWP::UserAgent have options for getting just the body or just the headers from a webpage?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
It's not a web page , it's a SOAP envelope.

I'll see if there is a method for striping the header, I guess this is why really I should be using the SOAP:Lite module, but I can't get it to work and the documentation sucks.

It seems to be quite a bug bear if you search google, everyone moans about the SOAP documentation, but even those people's example code doesn't work for me.

I'm not sure you can pass SOAP an XML envelope, it seems there are methods for creating the header, data etc..

Bit long winded for what i'm trying to acheive.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
It's not a web page , it's a SOAP envelope.

Yes, I used the wrong term. Why not use a SOAP module? Not that I have any experience with SOAP stuff.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
spot on Brigmar, many thanks.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top