代码之家  ›  专栏  ›  技术社区  ›  Echo says Reinstate Monica

获取/发布到RESTful Web服务

  •  20
  • Echo says Reinstate Monica  · 技术社区  · 15 年前

    我需要做一些从vb6到RESTful Web服务的获取和发布。最好和最简单的方法是什么?

    3 回复  |  直到 9 年前
        1
  •  29
  •   Matt Johnson-Pint    13 年前

    您需要添加对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
    
        2
  •  13
  •   craftworkgames    11 年前

    我最近在旧的遗留应用程序中需要这个来获取请求,因为接受的答案不能编译,所以我想发布一些工作代码。我相信它将来会帮助一些可怜的鞋底使用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)
    

    祝你快乐!:)

        3
  •  0
  •   Scott Lance    15 年前

    如果需要从REST Web服务获取/发布,只需将HTTP请求写入Web服务的URL即可:

    http://www.webservicehost.com/webserviceop?<any parameters>
    

    如果需要传递复杂对象,则需要将其序列化,然后将其作为参数传递。

    然后,您可以得到Web服务决定返回的任何格式的HTTP响应(JSON、XML等)。