我試圖通過API發送我的XML文件。發送XML文件錯誤'根級別的數據無效。第1行,第39位'
Data at the root level is invalid. Line 1, position 39.
沒有嘗試發送文件時,它的工作原理:我用下面的代碼,但是當我嘗試發送的文件上,它不會工作,我現在越來越在瀏覽器中完成這沒有問題:
' create the Xml that the Msxml2.serverXmlHttp object will send to the Webservice
dim Xml_to_Send
Xml_to_Send = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
Xml_to_Send = Xml_to_Send & "<xmldata>"
Xml_to_Send = Xml_to_Send & " <Products>"
Xml_to_Send = Xml_to_Send & " <ProductCode>THE-TEST</ProductCode>"
Xml_to_Send = Xml_to_Send & " <ProductPrice>100.00</ProductPrice>"
Xml_to_Send = Xml_to_Send & " </Products>"
Xml_to_Send = Xml_to_Send & "</xmldata>"
oXMLHttp.Send(Xml_to_Send)
但是,試圖將文件發送它不工作,這裏是完整的代碼。該文件從代碼複製上面的,所以我知道該文件是好的:
<%@ Page Title="MAIN" Language="vb" Explicit="true" AspCompat="true" %>
<%
Dim doc As XDocument = XDocument.Load("sample.xml")
' create the Msxml2.serverXmlHttp object needed to post the Xml to the WebService
Dim oXMLHttp
oXMLHttp = Server.CreateObject("Msxml2.serverXmlHttp")
oXMLHttp.open("POST", "http://www.mysite.com/net/[email protected]&EncryptedPassword=xxxx&Import=Update", False)
oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
oXMLHttp.setRequestHeader("Content-Action", "xmldata")
oXMLHttp.setTimeouts(100000, 100000, 600000, 9999999)
Server.ScriptTimeout = 10800
' Send the Xml
oXMLHttp.Send(String.Format("{0}\n\r{1}", doc.Declaration.ToString(), doc.ToString()))
' Receive the Xml
Dim Xml_Returned
Xml_Returned = oXMLHttp.responseText
' Validate the Xml
Dim xmlDoc
xmlDoc = Server.CreateObject("Msxml2.DOMDocument")
xmlDoc.loadXML(Xml_Returned)
If (Len(xmlDoc.text) = 0) Then
Xml_Returned = ("<BR><B>ERROR in Response xml:<BR>ERROR DETAILS:</B><BR><HR><BR>") & Xml_Returned
End If
' Display the Xml on the browser
Response.Write(Xml_Returned)
' clean up
Xml_to_Send = Nothing
oXMLHttp = Nothing
doc = Nothing
xmlDoc = Nothing
Xml_Returned = Nothing
%>
UPDATE 我已經更新從下面的響應上面的代碼。現在我得到的瀏覽器:
Data at the root level is invalid. Line 1, position 39.
這是我送的測試XML:
<xmldata>
<Products>
<ProductCode>AMN-ACE14</ProductCode>
<ProductPrice>3800.00</ProductPrice>
</Products>
</xmldata>
這是什麼語言以下行應使用一個XDocument做的伎倆?在vb [a]中,你不能在一行中聲明和賦值... –
對不起,它在.aspx頁面中使用VB – ToddN
你在做什麼?爲什麼要使用.NET程序中的XmlHttpRequest? –