tudley has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks, I am getting back into the perl world and have been given the task of comparing xml responses from 2 different Web Services and I am having trouble stripping off the response header from the Web Service. I feel comfortable dealing with the xml once the header is removed. My first thought was to use a regular expression, but that is turning out to be one ugly looking expr. I have the response saved as a string. Here's what I am looking to remove.
HTTP/1.1 200 OK Cache-Control: private, max-age=0 Date: Wed, 06 Jul 2011 15:19:14 GMT Server: Microsoft-IIS/7.5 Content-Length: 3490 Content-Type: text/xml; charset=utf-8 Client-Date: Wed, 06 Jul 2011 15:19:14 GMT Client-Peer: 172.23.192.20:80 Client-Response-Num: 1 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET
followed by the xml response. thanks in advance for your help, tudley

Replies are listed 'Best First'.
Re: help stripping header from a Web Service Response
by Corion (Patriarch) on Jul 06, 2011 at 16:54 UTC

    Have you looked at HTTP::Message?

    Also, what module are you using to send your web service request that doesn't already return a properly parsed response?

      I am updating previously written code. The original code simply took some raw xml and sent it using HTTP::Request Here's the code snipet.
      $userAgent = LWP::UserAgent->new(agent => 'perl post'); $file_contents = do { local $/; <INFILE> }; $message = $file_contents; $response = send_xml(); $xml_resp = $response->as_string; sub send_xml { my $request = HTTP::Request->new(POST => 'http://"servername".asmx +'); $request->header(SOAPAction => "https://"url"); $request->content($message); $request->content_type('text/xml; charset=utf-8'); my $response = $userAgent->request($request); $response; }
      obviously "servername" and "url" are just place holders to the real servers. Like I said, I am getting back into Perlville after a long break. thanks for the pointer to HTTP::Message which lead me to HTTP::Header. $xml_response contains the header I want to get rid of. I'll work on stripping it out when I get the response back.

        Why do you use $response->as_string instead of using $response->content or $response->decoded_content ? $response already is a HTTP::Response (which is a HTTP::Message), so you already have everything you need. You just should start using it.

Re: help stripping header from a Web Service Response
by muba (Priest) on Jul 06, 2011 at 23:31 UTC

    I've never really bothered with raw HTTP responses, but I do happen to know that the header and body of any HTTP message (be it request or response) are separated by an empty line. There are probably modules to do what you want, but it can't be that difficult anyway.

    $xml_resp = $response->as_string; $xml_resp =~ s/^.+?\n\n//; # this should do the trick.
Re: help stripping header from a Web Service Response
by locked_user sundialsvc4 (Abbot) on Jul 07, 2011 at 02:59 UTC

    Any Regexp::Common stuff that might be helpful?

    “Big, hairy” regular expressions are not so bad when someone else has written them ...   :-D

      Thanks all for the advice, I got it figured out and solved. @Corion, like I mentioned I am updating someone else's code. Part of my solution involved removing the as string portion. tudley