获取/发布到RESTful Web服务

Ech*_*ica 20 vb6 web-services

我需要从VB6对RESTful Web服务进行一些GET和POST.最好和最简单的方法是什么?

Jus*_*ner 29

您需要添加对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
Run Code Online (Sandbox Code Playgroud)


cra*_*mes 13

我最近在一个旧的遗留应用程序中需要这个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
Run Code Online (Sandbox Code Playgroud)

以下是示例用法:

Dim result As String
Dim url As String

url = "http://my.domain.com/service/operation/param"
result = WebRequest(url)
Run Code Online (Sandbox Code Playgroud)

快乐的VB6ing!:)

  • 哈哈。我完全同意。毕竟它是 2017 年[最可怕的语言](https://stackoverflow.com/insights/survey/2017/#technology-most-loved-dreaded-and-wanted-languages);) (2认同)