RE: HTTP Post and Multipart


Have you tried using tcpmon (or similar) to see what the request headers and payload look like?

When you are "retrieving" the PDF files from the file system using the first p:http-request, you use "text/plain" as the override-content-type. Does this actually work for you? I would expect that the c:body document that you get contains complete rubbish. The effect of using "text/plain" is that the binary PDF data will be converted to a sequence of Unicode characters. Because you don't provide character encoding information with the content type, the p:http-request will most likely interpret the bytes as "ISO-8859-1", but any other encoding will result into equally broken (or at least unusable) results, IMHO.

I think the proper way would be to "retrieve" the PDF data as "application/pdf" (or any binary content type) and let p:http-request base64 encode the c:data document for you. In the second p:http-request that makes the multipart request, I would insert the base64-encoded c:body into the c:multipart element. You may need to massage the c:body attributes a bit before you insert it in the c:multipart, though.


Vojtech Toman
Consultant Software Engineer
EMC | Information Intelligence Group

From: [] On Behalf Of Philip Fennell
Sent: Wednesday, March 23, 2011 9:24 PM
To: XProc Dev
Subject: HTTP Post and Multipart


I have a pipeline (see below) which attempts to upload PDF files from the file system to a web service using the service's API. The API requires that multipart/form-data POSTs are used.

Currently I get a series of HTTP 500 status responses. As the API isn't very detailed in its responses I don't know if the problem lies in the encoding of the body or how the multipart has been constructed.

I have tried sending the PDFs as content-type="text/plain" and content-type="application/octet-stream" encoding="base64" but both ways get me the same response. If I change to multipart/mixed the it complains bitterly so at least I know I haven't got that part wrong. I'm assuming that something a browser does when it sends multipart/form-data is not what's happening here.

I'm doing something wrong, that's for sure, but what that is I don't know. Does anyone have any ideas?

I'm using the most recent Calabash from within oXygen 12.1 on Windows 7.



<?xml version="1.0" encoding="UTF-8"?>

  <p:output port="result"/>

  <p:serialization port="result" encoding="UTF-8" indent="true"
    media-type="application/xml" method="xml"/>

  <p:import href="../lib/library-1.0.xpl"/>

  <p:directory-list name="content" path="test/resources/assets" include-filter=".*\.pdf"/>

  <p:make-absolute-uris name="directory" match="//c:file/@name">
    <p:with-option name="base-uri" select="/c:directory/@xml:base"/>

    <p:iteration-source select="/c:directory/c:file"/>
    <p:identity name="fileRef"/>

    <p:document-template name="get-request">
      <p:input port="template">
         <c:request method="GET" href="{/c:file/@name}" override-content-type="text/plain"/>
      <p:input port="source"/>
      <p:input port="parameters">

    <p:http-request name="retrieve"/>

    <p:document-template name="post-request">
      <p:input port="source"/>
      <p:input port="template">
          <c:request method="POST"
            <c:multipart content-type="multipart/form-data" boundary="=-=-=-=-=">
      <p:input port="parameters">

    <p:http-request name="create"/>


  <p:wrap-sequence wrapper="c:result"/>

Received on Thursday, 24 March 2011 13:55:49 UTC