我在VB6中有很好的工作代码。但我需要发布xml文件utf-8编码(包括cyrilic)。所以我想将代码转换为VB.NET,但结果是错误500 - 内部服务器错误
原始vb6代码(succesfull witchout cyrilic):
Dim o As New xmlHttp
xmlContent() = fs.GetFileContent(Replace(Me.txtOutputFileName.Text, fs.GetFileNameByPath(Me.txtOutputFileName.Text), "") & xmlFileNames(i))
xmlString = MFunctions.GetString(xmlContent())
o.Open "POST", server, False, EE_XML_EXCHANGE_ID, EE_XML_EXCHANGE_PWD
o.setRequestHeader "Content-Type", "text/xml" ' "text/xml;charset=utf-8"
o.setRequestHeader "SOAPAction", ""
o.send xmlString
Me.txtResponseHeaders = o.getAllResponseHeaders
Me.txtResponse = o.responseText
VB.NET代码(返回错误500 - 内部服务器错误):
Dim xdoc As XDocument = XDocument.Load("z:\Operations\RU\_TEST\xml\send\RUWP121001_01_05_01.xml")
Dim request As WebRequest = WebRequest.Create("http://217.159.234.77:8080/epmx/services/messagesService")
request.Method = "POST"
Dim postData As String = xdoc.ToString
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "text/xml"
request.ContentLength = byteArray.Length
request.Credentials = New System.Net.NetworkCredential(EE_XML_EXCHANGE_ID,EE_XML_EXCHANGE_PWD)
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
reader.Close()
dataStream.Close()
response.Close()
知道问题是什么?
谢谢