Get/post to RESTful web service

前端 未结 3 1464
北海茫月
北海茫月 2020-12-01 11:09

I need to do some GETing and POSTing to a RESTful web service from VB6. What is the best and simplest way to do that?

3条回答
  •  盖世英雄少女心
    2020-12-01 11:23

    I needed this for GET requests in an old legacy application recently, and since the accepted answer doesn't compile I thought I'd post some working code. I'm sure it will help some poor sole using VB6 in the future ;) Here's a nice clean function.

    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
    

    And here's example usage:

    Dim result As String
    Dim url As String
    
    url = "http://my.domain.com/service/operation/param"
    result = WebRequest(url)
    

    Happy VB6ing! :)

提交回复
热议问题