I'm having an issue with trying to use VB.NET and the WebRequest object to post some cXML text and an attachment. I believe I am formatting the text of the data I wish to post correctly, as it matches samples Ariba has supplied. What I am uncertain of is if I am correctly using the WebRequest object to do the posting. I am setting the Method as "POST" and the ContentType as "multipart/mixed". I can successfully post cXML (using a ContentType of "text/xml"), so I know posting in general works. The message I get back from Ariba is "The document could not be parsed: Missing start boundary [ANCLS-741552]", however, as the following code shows, there is a start boundary. I have removed some proprietary data and replaced it with "...". Following the MIME text, I have included the relevant VB.NET code I am using.
Any and all suggestions are most welcome and appreciated!
------=_boundary.20100210154837663.173702
Content-Type: text/xml; charset=UTF-8
Content-ID: Part1.5213.20100210154837663.319349
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.018/cXML.dtd">
<cXML.../cXML>
------=_boundary.20100210154837663.173702
Content-Type: application/octet-stream
Content-transfer-encoding: base64
Content-ID: 5213.20100210154837663.319349
Content-Disposition: attachment; filename=attachment_20100210154837663_125705.jpg
Content-Length: 5660
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAd
.
.
.
dC2Nz9dOaQ1ZVIilwIpaWvLEg7aWuauv/9k=
------=_boundary.20100210154837663.173702--
Dim myWriter As StreamWriter = Nothing
Dim strUri As String = "https://service.ariba.com/service/transaction/cxml.asp"
Dim WebReq As WebRequest = System.Net.WebRequest.Create(strUri)
WebReq.Method = "POST"
WebReq.ContentType = "multipart/mixed"
myWriter = New StreamWriter(WebReq.GetRequestStream())
myWriter.Write(xmlText)
myWriter.Close()
Dim WebRsp As HttpWebResponse
WebRsp = CType(WebReq.GetResponse(), HttpWebResponse)