Web service connection RRS feed

All replies

  • Hi,

    I use the HTTPRequest Class. Hope it helps...

    Thursday, November 3, 2016 5:47 PM
  • Here's an example from my blog: Retrieve Internet Date and Time

    Hope it helps...

    Thursday, November 3, 2016 5:50 PM
  • Hi yinkamax,

    Here below is an another example of that.

    Function GetDirections(Origin As String, Destination As String) As String
        ' Create a WebClient for executing requests
        ' and set a base url that all requests will be appended to
        Dim MapsClient As New WebClient
        MapsClient.baseURL = ""
        ' Use GetJSON helper to execute simple request and work with response
        Dim Resource As String
        Dim Response As WebResponse
        Resource = "directions/json?" & _
            "origin=" & Origin & _
            "&destination=" & Destination & _
        Set Response = MapsClient.GetJSON(Resource)
        ' => GET https://maps.../api/directions/json?origin=...&destination=...&sensor=false
        ProcessDirections Response
    End Function
    Public Sub ProcessDirections(Response As WebResponse)
        If Response.StatusCode = WebStatusCode.Ok Then
            Dim Route As Dictionary
            Set Route = Response.Data("routes")(1)("legs")(1)
            Debug.Print "It will take " & Route("duration")("text") & _
                " to travel " & Route("distance")("text") & _
                " from " & Route("start_address") & _
                " to " & Route("end_address")
            Debug.Print "Error: " & Response.Content
        End If
    End Sub


    Web Service Example using VBA

    another example:

    Public Sub GetPerson()
        'For API
        Dim reader As New XMLHTTP60
        reader.Open "GET", "", False
        reader.setRequestHeader "Accept", "application/json"
        Do Until reader.ReadyState = 4
        If reader.Status = 200 Then
            MsgBox (reader.responseText)
            MsgBox "Unable to import data."
        End If
    End Sub

    Note: Add reference to Microsoft XML 6.0



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, November 4, 2016 5:08 AM