1

我在 VB6 中有很好的工作代码。但我需要发布 xml 文件 utf-8 编码(包括西里尔字母)。所以我想将代码转换为 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()

有什么问题吗?

谢谢

4

0 回答 0