none
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 = "https://maps.googleapis.com/maps/api/"
    
        ' 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 & _
            "&sensor=false"
        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")
        Else
            Debug.Print "Error: " & Response.Content
        End If
    End Sub

    Reference:

    Web Service Example using VBA

    another example:

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

    Note: Add reference to Microsoft XML 6.0

    Regards

    Deepak


    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 MSDNFSF@microsoft.com.


    Friday, November 4, 2016 5:08 AM
    Moderator