I need to generate a post http request that sends to a domino server a bunch of form data including one or more upload files. In other words, I am trying to mimic the behavior of submission of this type of form:
<form method="POST" action="http://domino/appname.nsf/M?CreateDocument +" enctype="multipart/form-data"> <input type="text" name="FirstName" value="John"> <input type="text" name="LastName" value="Doe"> <input type="file" name="%%File7cfd40fb9757495b85256cf0007322bb.$Body. +0.7128" value="word.doc"> </form>
To accomplish this, I wrote:
#!/usr/local/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Headers; my $q = new CGI; print "Content-type: text/html\n\n"; my $agent = new LWP::UserAgent; $result = $agent->request( POST 'http://domino/appname.nsf/M?CreateDocument', Content_Type => 'form-data', Content => [ FirstName => 'John', LastName => 'Doe', '%%File7cfd40fb9757495b85256cf0007322bb.$Body +.0.7128' => ["/web/docroot/word.doc"] ]); print "all is well.\n\n" if $result->is_success;
All data posts fine (including the attached file), except that using the html method (the first code fragment), the file is readable in MS Word when downloaded from domino, while using the perl request method, the file comes out as garbage on the domino side. I noticed that there was a header in the garbage-d file that read: Content-Type: application/octet-stream which I'm assuming is the default. I tried to remedy the situation by changing ["/web/docroot/word.doc"] to ["/web/docroot/word.doc","word.doc",'Content-type' => 'application/msword'] in the second code fragment. The transferred file still comes out of domino as garbage though, although the header in the garbage-d file now reads: Content-Type: application/msword I also thought that the wacky domino form field name for the upload file could have something to do with the problem, but the file does get uploaded and associated with the correct record. It seems that there may be other header entries I may need to set in the HTTP::Request::Common object for the upload field to get the encoding or whatever set right for the MS Word doc. Btw, both the perl script and domino server are running on solaris (SunOS 5.7). I would greatly appreciate any comments.

In reply to word doc headers in HTTP::Request::Common by Anonymous Monk

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.