我在将MIME内容的XML张贴到Ariba SN时遇到类似的错误。在没有MIME的情况下发布XML很有效。
的错误味精,我得到的是: 文档无法解析:内容是不是在序言不允许的。 (第1行,第1列)ANCLS-741552]
我尝试上传的XML是:
------=_Part_19_14056801.1265738936575
Content-Type: text/xml; charset=UTF-8
Content-Disposition: attachment; filename=TestMessage020910.xml
Content-ID:
?<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.021/InvoiceDetail.dtd">
<cXML>...</cXML>
------=_Part_19_14056801.1265738936575
Content-Type: image/tiff
Content-transfer-encoding: binary
Content-ID: TestImageURL
Content-Disposition: attachment; filename=TestImageURL.tif
Content-Length: 23618
II*? [??&?lDr#??292??292?`?????pr9?3][email protected]?r9?A?a?A??h4?B?d;? r1?
.
.
????[?????????(???????1?7????[??2????.\[email protected]????????????????%?? ????%?? ?Pixel Translations Inc., PIXTIFF Version 57.0.218.2183??2007:12:11 09:55:11?
------=_Part_19_14056801.1265738936575--
????????????????????????????????????????????????????????????????????????????????????????????
.
.
????????????????????????????????????????????????????????????????????????????????????????????
我使用的VB.Net代码:
Private Function Post_XML(ByVal XmlFile As String) As String
If XmlFile.Length = 0 Then
MsgBox("Error: XML File cannot be blank", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
Return ""
End If
If File.Exists(XmlFile) = False Then
MsgBox("Error: File does not exist - " + XmlFile, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
Return ""
End If
Dim ASN_Link As String = "https://service.ariba.com/service/transaction/cxml.aspx"
rtbLog.Text = ""
System.Threading.Thread.Sleep(1000)
rtbLog.Text = rtbLog.Text & vbCrLf & "To " & ASN_Link & vbCrLf
Dim sr As StreamReader = New StreamReader(XmlFile)
Dim XMLRead As String = sr.ReadToEnd
Dim stXML As String
stXML = XMLRead
sr.Close()
Try
Dim results As String
Dim request As WebRequest = WebRequest.Create(ASN_Link)
request.Method = "POST"
request.ContentType = "text/xml; charset=utf-8"
Dim proxyObject As WebProxy = New WebProxy("proxy.xyz.com:8080", True)
proxyObject.Credentials = CredentialCache.DefaultCredentials
request.Proxy = proxyObject
request.PreAuthenticate = True
results = WriteToURL(request, stXML)
Dim Response As String
Response = RetrieveFromURL(request)
rtbLog.Text = rtbLog.Text & vbCrLf & Response
Return "OK"
Catch ex As Exception
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK)
Return "Error"
Exit Function
End Try
End Function
Private Function WriteToURL(ByVal Request As WebRequest, ByVal data As String) As String
Try
'Dim bytes = System.Text.Encoding.ASCII.GetBytes(data)
Dim bytes = System.Text.Encoding.UTF8.GetBytes(data)
Request.ContentLength = bytes.Length
Dim OutPutStream As Stream = Request.GetRequestStream
OutPutStream.Write(bytes, 0, bytes.length)
OutPutStream.Close()
Return "Ok"
Catch ex As Exception
MessageBox.Show(ex.Message & " - Write To URL", "error", MessageBoxButtons.OK)
Return "Error"
Exit Function
End Try
End Function
Private Function RetrieveFromURL(ByVal Request As WebRequest) As String
Try
Dim response As WebResponse = Request.GetResponse
Dim stream As Stream = response.GetResponseStream
Dim sr As StreamReader = New StreamReader(stream)
Return sr.ReadToEnd
Catch ex As Exception
MessageBox.Show(ex.Message & " - Retrieve From URL", "", MessageBoxButtons.OK)
Return "Error"
Exit Function
End Try
End Function
一句我看到(我的确收到的时候我还没有做出这种改变的错误)的事情是,对于一个MIME文件将contentType必须多/混合或多重/相关,而不是文/ XML。或者,至少它不应该是text/xml,而应该是我不知道的其他东西。尽管如此,cXML的文档看起来很清楚。希望有所帮助,并感谢张贴。你永远不知道解决方案的想法可以从哪里来! – Bill 2010-02-11 13:13:43