473,749 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LWP::UserAgent get just body content(image)

4 New Member
Hi all,
I am attempting to use the LWP::UserAgent to request a Soap call, and in the response the request returns a TIFF image. When I write the contents out to a file(binary mode), the file also contains header information. How would I go about extracting just the body(TIF image) of the response?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use Data::Dumper;
  5. use LWP::UserAgent;
  6.  
  7. my $type = "TIFF";
  8. my $ua = new LWP::UserAgent;
  9. my $service = "http://ops.epo.org//soap-services/document-retrieval";
  10.  
  11. my $content = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ops="http://ops.epo.org">';
  12. $content = $content . '<soapenv:Header/>';
  13. $content = $content . '<soapenv:Body>';
  14. $content = $content . "<ops:document-retrieval id=\"EP        1000000A1 I \" page-number=\"1\" document-format=\"SINGLE_PAGE_$type\" system=\"ops.epo.org\">";
  15. $content = $content . '</ops:document-retrieval>';
  16. $content = $content . '</soapenv:Body>';
  17. $content = $content . '</soapenv:Envelope>';
  18.  
  19. my $header = new HTTP::Headers (
  20.         'Content-Type'   => 'text/xml; charset=utf-8',
  21.         'SOAPAction'     => 'document-retrieval',
  22.    );
  23.  
  24. my $req = new HTTP::Request('POST',$service,$header,$content);
  25. my $res = $ua->request($req);
  26. print "request string:\n". $req->as_string."\n";
  27.  
  28. print "content type: ". $res->content_type."\n";
  29. print "header = ". $res->headers_as_string()."\n";
  30.  
  31. #my $response = $res->headers_as_string();
  32. #my $response .= $res->content;
  33. #print "---response---\n$response\n";
  34.  
  35. #my ($body,$mime);
  36. #eval
  37. #{
  38. #   $mime = $res->parts([1]);
  39.    #$body = $mime->body_handle();
  40. #};
  41. #if ($@)
  42. #{ die "error: $@\n"; }
  43.  
  44. if ($res->is_success)
  45. {
  46.   my $dlfile = "file.$type";
  47.   open(OUT, ">$dlfile") or die "whoops $!";
  48.   binmode(OUT);
  49.   print OUT $res->content;
  50.   close OUT;
  51. }
  52. else
  53. { warn "request failed...\n"; }
  54.  
  55.  
Output:

request string:
POST http://ops.epo.org//soap-services/document-retrieval
User-Agent: libwww-perl/5.834
Content-Type: text/xml; charset=utf-8
SOAPAction: document-retrieval

<soapenv:Envelo pe xmlns:soapenv=" http://schemas.xmlsoap .org/soap/envelope/" xmlns:ops="http ://ops.epo.org"><s oapenv:Header/><soapenv:Body> <ops:document-retrieval id="EP 1000000A1 I " page-number="1" document-format="SINGLE_ PAGE_TIFF" system="ops.epo .org"></ops:document-retrieval></soapenv:Body></soapenv:Envelop e>

content type: multipart/related
header = Connection: close
Date: Wed, 14 Apr 2010 13:31:58 GMT
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Server: Apache
Content-Type: multipart/related; boundary="----=_Part_901910_5 14465450.127125 1918535"; type="text/xml"
Client-Date: Wed, 14 Apr 2010 13:32:00 GMT
Client-Peer: 145.64.132.201: 80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
SOAPAction: ""
X-Powered-By: Servlet 2.4; JBoss-4.3.0.GA (build: SVNTag=JBPAPP_4 _3_0_GA date=2008010315 48)/Tomcat-5.5

Top few lines of TIFF file:

------=_Part_901910_5 14465450.127125 1918535
Content-Type: text/xml; charset=utf-8

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap .org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ops:w orld-patent-data xmlns="http://www.epo.org/exchange" xmlns:ops="http ://ops.epo.org"><o ps:meta name="elapsed-time" value="42"/><ops:documen t-retrieval document-format="SINGLE_ PAGE_TIFF" id="EP 1000000A1 I " page-number="1" system="ops.epo .org"><ops:desc >FullDocument </ops:desc><ops:c ontent-ref>EP 1000000A1 I .tiff</ops:content-ref></ops:document-retrieval></ops:world-patent-data></SOAP-ENV:Body></SOAP-ENV:Envelope>
------=_Part_901910_5 14465450.127125 1918535
Content-Type: application/tiff
Content-ID: EP 1000000A1 I .tiff
Content-Transfer-Encoding: binary


Thanks for any replies!
Apr 14 '10 #1
0 1887

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2489
by: Pawel Banys | last post by:
Hello, There is a form which contains the following element: <FORM name="testForm" method="post" action="http://server/some_script"> ......../ some standard entry fields /....... <input type="image" name="img_submit" src="click.jpg" alt="click on me"> </form> When that image is clicked on the webpage, the "some_script" is called and
7
6767
by: JavaScriptRocks | last post by:
I've been trying to imitate / reverse engineer the add attachment feature in gmail composer. I managed to do it to say about 80% but its giving me trouble in IE on WinXP-Sp2. I am using PHP to do the upload. It works well on Firefox/DeerPark, but in IE, the file selected just vanishes. You can verify it by commenting the lines marked "//IE Trouble". Commenting those lines will remove IE specific code, except the el.click() whick sends the...
0
2549
by: sharif | last post by:
Anyone could help me out for n=my code ......I have written following code ,Here i m able to get and post the form successfuly..but after posting im not gettng proper response content... #!usr/bin/perl -w use strict; use LWP; use LWP::Simple; use LWP::UserAgent; use HTML::Form; use Switch; use HTTP::Cookies;
0
2801
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or HTML mails with attachments, but some mail clients are not able to display the html mails that is why I need to send multipart alternative emails, when I used multipart/alternative then I'm not able to send attachments and if I use the multipart/mixed...
9
2272
by: perls | last post by:
"Newbie needs help" Hi all, I had a programmer do a site scraping script for me.. the aim was to scrape data from 5 different sites and upload directly into my website databse. I started to study the five .pl files and found that there is only small changes in the files e.g. ( the url from the site to be scraped changes for obvious reasons etc. ) There is also a few other lines of code which I dont understand. I would like to be able to...
4
4230
by: kkamath | last post by:
Hi, I use LWP::UserAgent to automate windows login process. I set the credentials using $ua->credentials("host:port","realm","id","password"); but it fetches only the current page requested. It fails for subsequent requests and pops up the windows form again to supply the credentials. I have created a cookie jar too but this doesnt help as the authentication is not sticking. Any help on this is highly appreciated. The code is as follows. ...
1
2861
by: andrewwan1980 | last post by:
I need help in parsing unicode webpages & downloading jpeg image files via Perl scripts. I read http://www.cs.utk.edu/cs594ipm/perl/crawltut.html about using LWP or HTTP or get($url) functions & libraries. But the content returned is always garbled. I have used get($url) on a non-unicode webpage and the content is returned in perfect ascii. But now I want to parse http://www.tom365.com/movie_2004/html/5507.html and the page I get back is...
0
9568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.