VB.NET 中的 MSXML [英] MSXML in VB.NET
本文介绍了VB.NET 中的 MSXML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码在旧的 VB6 中运行良好.我在 VB.NET 中尝试了各种方法来做到这一点,但无法让它工作.任何人都可以帮我编写在 .NET 中运行的代码吗?
This code works well in good old VB6. I have tried all kinds of ways to do this in VB.NET but can't get it to work. Can anyone help me with code that works in .NET please?
Dim objHTTP As New MSXML2.XMLHTTP
Dim strReturn As String
Dim objReturn As New MSXML2.DOMDocument
Dim url As String
Dim XMLEnvelope As String
url = "http://zzzzzdummy.com"
XMLEnvelope = vbNull
objHTTP.open("post", url, False, "", "") '
Debug.Print(Err.Number)
objHTTP.setRequestHeader("Content-Type", "text/xml")
objHTTP.setRequestHeader("Content-length", Len(XMLEnvelope))
Debug.Print("------------Send Envelope-------------")
Debug.Print(XMLEnvelope)
Debug.Print("--------------------------------------")
objHTTP.send(XMLEnvelope)
strReturn = objHTTP.responseText
objReturn.loadXML(strReturn)
Debug.Print("----------Response Envelope-----------")
Debug.Print(strReturn)
Debug.Print("--------------------------------------")
推荐答案
这是我想到的.来自此的响应然后我可以进入 XML 返回并解析它.
This is what I came up with. The response from this I can then go into the XML return and parse it.
Function WRequest(ByVal URL As String, ByVal method As String, ByVal POSTdata As String) As String
Dim responseData As String = ""
Try
Dim hwrequest As Net.HttpWebRequest = Net.WebRequest.Create(URL)
hwrequest.Accept = "*/*"
hwrequest.AllowAutoRedirect = True
hwrequest.UserAgent = "http_requester/0.1"
hwrequest.Timeout = 60000
hwrequest.Method = method
If hwrequest.Method = "POST" Then
hwrequest.ContentType = "application/x-www-form-urlencoded"
Dim encoding As New Text.ASCIIEncoding() 'Use UTF8Encoding for XML requests
Dim postByteArray() As Byte = encoding.GetBytes(POSTdata)
hwrequest.ContentLength = postByteArray.Length
Dim postStream As IO.Stream = hwrequest.GetRequestStream()
postStream.Write(postByteArray, 0, postByteArray.Length)
postStream.Close()
End If
Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
Dim responseStream As IO.StreamReader = New IO.StreamReader(hwresponse.GetResponseStream())
responseData = responseStream.ReadToEnd()
End If
hwresponse.Close()
Catch e As Exception
responseData = "An error occurred: " & e.Message
End Try
Return responseData
End Function
这篇关于VB.NET 中的 MSXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文