I am getting the error:
An error was found while parsing the multipart request. Boundary terminator '--BOUNDARY--' was not found in the request.
I have tried debugging with Firefox and chrome with same results. Any help would be greatly appreciated.
Here is the code I am using:
Public Sub configureMultiPartFormDataRequest(ByVal request As HttpWebRequest, _
ByVal xmlBody As String, _
ByVal docName As String)
'Overwrite the default content-type header and set a boundary marker
request.ContentType = "multipart/form-data; boundary=BOUNDARY"
'Start building the multipart request body
Dim requestBodyStart As String = "\r\n\r\n--BOUNDARY\r\n" + _
"Content-Type: application/xml\r\n" + _
"Content-Disposition: form-data\r\n" + _
"\r\n" + _
xmlBody + "\r\n\r\n--BOUNDARY\r\n" + _
"Content-Type: application/pdf\r\n" + _
"Content-Disposition: file; filename=\" + docName + " \ documentId=1\r\n" + _
"\r\n"
Dim requestBodyEnd As String = "\r\n--BOUNDARY--\r\n\r\n"
'Read the contents of provided document into the request stream
Dim fileStream As FileStream = File.OpenRead(docName)
'Write the body of the request
Dim bodyStart() As Byte = System.Text.Encoding.UTF8.GetBytes(requestBodyStart.ToString())
Dim bodyEnd() As Byte = System.Text.Encoding.UTF8.GetBytes(requestBodyEnd.ToString())
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(bodyStart, 0, requestBodyStart.ToString().Length)
'Read the file contents and write them to the request stream. (4096 Byte Blocks)
Dim buf(4096) As Byte
'Dim len As Integer
'While ((len = fileStream.Read(buf, 0, 4096)) > 0)
' dataStream.Write(buf, 0, len)
'End While
Dim bytesRead As Integer
Do
bytesRead = fileStream.Read(buf, 0, buf.Length)
If bytesRead > 0 Then
dataStream.Write(buf, 0, bytesRead)
End If
Loop While bytesRead > 0
dataStream.Write(bodyEnd, 0, requestBodyEnd.ToString().Length)
dataStream.Close()
End Sub
Added 05/09/2014 Here is the actual request text from Fiddler2. It appears that the bodyEnd is being set to "PDF-1.7". I have searched the code for this string without success. Thanks for your help: \r\n\r\n--BOUNDARY\r\nContent-Type: application/xml\r\nContent-Disposition: form-data\r\n\r\nsentDocuSign API - Embedded Signing example1\10.1.11.100\SecureDocs\EnrollmentForms\CrystalReport1.pdf1hmitchell@ata.eduA Adams10010011\r\n\r\n--BOUNDARY\r\nContent-Type: application/pdf\r\nContent-Disposition: file; filename=\XXX\; documentId=1\r\n\r\n%PDF-1.7
David Thanks for your fix for the BOUNDARY error. I implemented your xml example and now get an error: "The document element did not contain the encoded document, or there is a problem with the encoding." Here is the request: --BOUNDARY Content-Type: application/xml Content-Disposition: form-data
sentDocuSign API - Embedded Signing example1C:\Hold\myXML.xml1hmitchell@ata.eduA Adams10010011
--BOUNDARY Content-Type: application/pdf Content-Disposition: file; filename=\C:\Hold\myXML.xml \ documentId=1
<nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>
--BOUNDARY--
Thanks for your help!!!