#!/usr/bin/perl -w # I am having difficulty with using SOAP with MIME attachments, # possibly due to a "binary attachment" done outside a soap # envelope. # Can someone tell me what I am doing wrong with this MIME::Entity , # so that I do not get an uncorrupted tiff or pdf file? # The soap service is documented at http://ops.espacenet.com/ , # under "Input Examples" as "DocumentRetrieval"- but you probably # do not need that, see the code below. # Thanks. # To run, cut and paste and s/\n\+//g #!/usr/bin/perl -w use SOAP::Lite ; # +trace => ['debug'] ; use MIME::Entity; use Data::Dumper; my $soap = SOAP::Lite->new(); $soap-> proxy('http://ops.espacenet.com/OpenPatentServices/webService' +); $soap-> ns('urn:EPO-OpenPatentServices-documentData'); $soap-> service('http://ops.espacenet.com/OpenPatentServices/webServic +e/getPatentData?wsdl'); my $req_xml; my $som; $req_xml = '<OpenPatentServices ACTION="DocumentRetrieval"><WORLDPATE +NTDATA><DOCUMENT ID="EP 1000000PAFP " SYSTEM="BNS" FORMAT="SINGLE_P +AGE_TIFF" PAGE_NUMBER="1"/></WORLDPATENTDATA></OpenPatentServices>'; #$req_xml = '<OpenPatentServices ACTION="DocumentRetrieval"><WORLDPAT +ENTDATA><DOCUMENT ID="EP 1000010A0 I " SYSTEM="BNS" FORMAT="SINGLE_ +PAGE_PDF" PAGE_NUMBER="1"/></WORLDPATENTDATA></OpenPatentServices>'; $som = $soap->getDocumentData($req_xml); my $mime_entity = ${$som->parts}[0]; my $body = $mime_entity->bodyhandle; print 'mime_entity "', Dumper $mime_entity , "\"\n" ; print 'binmode: ',$body->binmode(), ' -> '; #$body->binmode(1); print $body->binmode(1), "\n"; print 'is_encoded: "',$body->is_encoded(), '" -> '; print $body->is_encoded(0), "\n"; open ( OUT , '>1.tif' ) or die "whoops $!" ; #open ( OUT , '>1.pdf' ) or die "whoops $!" ; print OUT $body->as_string; close OUT; print "Done!\n"; exit; # typical output- and a corrupted 1.tif file. __DATA__ mime_entity "$VAR1 = bless( { 'ME_Bodyhandle' => bless( { 'MBC_Data' => [ 'binary data removed' ], 'MB_Binmode' => 1 }, 'MIME::Body::InCore' ), 'ME_Parts' => [], 'mail_inet_head' => bless( { 'mail_hdr_foldlen' => 79 +, 'mail_hdr_modify' => 0, 'mail_hdr_list' => [ 'Co +ntent-Type: application/octet-stream ', 'Co +ntent-Transfer-Encoding: binary ', 'Co +ntent-Id: <EP 1000000PAFP .tiff> ', 'Co +ntent-Location: EP 1000000PAFP .tiff ' ], 'mail_hdr_hash' => { 'Co +ntent-Type' => [ + \$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[0] + ], 'Co +ntent-Location' => [ + \$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[3] + ], 'Co +ntent-Transfer-Encoding' => [ + \$VAR1->{'mail_inet_head'}{'mail_hdr_li +st'}[1] + ], 'Co +ntent-ID' => [ + \$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[2] + ] }, 'mail_hdr_mail_from' => +'KEEP', 'mail_hdr_lengths' => {} }, 'MIME::Head' ) }, 'MIME::Entity' ); $VAR2 = '" '; Use of uninitialized value in print at P:/workspace/scripts/trunk/monk +s.pl line 36. binmode: 1 -> 1 is_encoded: "" -> 0 Done!

In reply to SOAP::Lite / MIME::Entity are messing with me? (and/or possibly I am an idiot) by mw487

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.