我需要从VB6对RESTful Web服务进行一些GET和POST.最好和最简单的方法是什么?
您需要添加对MSXML库的引用:
Dim sUrl As String Dim response As String Dim xmlhttp Set sUrl = "http://my.domain.com/service/operation/param" Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP") xmlhttp.open "POST", sURL, False xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.send() Dim response As String = xmlhttp.responseText Set xmlhttp = Nothing
我最近在一个旧的遗留应用程序中需要这个GET请求,并且由于接受的答案没有编译,我想我会发布一些工作代码.我相信它将来会帮助一些使用VB6的可怜鞋底;)这是一个很好的清洁功能.
Public Function WebRequest(url As String) As String Dim http As MSXML2.XMLHTTP Set http = CreateObject("MSXML2.ServerXMLHTTP") http.Open "GET", url, False http.Send WebRequest = http.responseText Set http = Nothing End Function
以下是示例用法:
Dim result As String Dim url As String url = "http://my.domain.com/service/operation/param" result = WebRequest(url)
快乐的VB6ing!:)