Your code snippet above is missing the calling method so I made my own as shown below to demonstrate how to leverage WebHookapp endpoint to capture what is being sent. So I think you will see that the body is not formatted correctly due to the fact you tried to "escape" the line breaks and carriage return values vs using the chr with the correct value.
Code I added to call you above method
Imports System.IO
Imports System.Net
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myHTTPRequest As System.Net.HttpWebRequest = WebRequest.Create("http://webhookapp.com/1037371688646089664")
Dim myXML As String = "{SomeXMLorJason: sampleNotFormatedcorrectly}"
Dim myDocName As String = "c:\myXML.xml"
myHTTPRequest.Method = "POST"
configureMultiPartFormDataRequest(myHTTPRequest, myXML, myDocName)
myHTTPRequest.GetResponse()
End Sub
'Your Code goes here ---> from above:
End Class
What is in the file c:\myXML.xml
<nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>
What was sent:
POST /1037371688646089664
content-type multipart/form-data; boundary=BOUNDARY
host webhookapp.com
content-length 439
expect 100-continue
connection Keep-Alive
\r\n\r\n--BOUNDARY\r\nContent-Type: application/xml\r\nContent-Disposition: form-data\r\n\r\n{SomeXMLorJason: sampleNotFormatedcorrectly}\r\n\r\n--BOUNDARY\r\nContent-Type: application/pdf\r\nContent-Disposition: file; filename=\c:\myXML.xml \ documentId=1\r\n\r\n <nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>\r\n--BOUNDARY--\r\n\r\n
What to do to fix your code:
'Start building the multipart request body
' http://www.asciitable.com/
Dim asciLN As String = Chr(10)
Dim asciCR As String = Chr(13)
Dim requestBodyStart As String = asciCR + asciLN + asciCR + asciLN + "--BOUNDARY" + asciCR + asciLN + _
"Content-Type: application/xml" + asciCR + asciLN + _
"Content-Disposition: form-data" + asciCR + asciLN + _
asciCR + asciLN + _
xmlBody + asciCR + asciLN + asciCR + asciLN + "--BOUNDARY" + asciCR + asciLN + _
"Content-Type: application/pdf" + asciCR + asciLN + _
"Content-Disposition: file; filename=\" + docName + " \ documentId=1" + asciCR + asciLN + _
asciCR + asciLN
Dim requestBodyEnd As String = asciCR + asciLN + "--BOUNDARY--" + asciCR + asciLN + asciCR + asciLN
Which will yield:
POST /1037371688646089664
content-type multipart/form-data; boundary=BOUNDARY
host webhookapp.com
content-length 409
expect 100-continue
connection Keep-Alive
--BOUNDARY
Content-Type: application/xml
Content-Disposition: form-data
{SomeXMLorJason: sampleNotFormatedcorrectly}
--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename=\c:\myXML.xml \ documentId=1
<nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>
--BOUNDARY--
And a general envelope in JSON as Multipart should look like below:
POST http://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes
X-DocuSign-Authentication: <DocuSignCredentials><Username>{name}</Username><Password>{password}</Password><IntegratorKey>{integrator_key}</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: multipart/form-data; boundary=AAA
--AAA
Content-Type: application/json
Content-Disposition: form-data
{
"status":"sent",
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject - EnvelopeDefFull",
"documents": [{
"name": "test1.pdf",
"documentId":"1"
"order":"1"
}],
"recipients": {
"signers" : [{
"email": "test@email.com",
"name": "Sally Doe",
"recipientId":"1",
}]
}
}
--AAA
Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf";documentid=1
<document bytes removed>
--AAA--