Thursday, January 22, 2015

REST GET

http://stackoverflow.com/questions/24975513/vba-excel-winhttprequest-returning-empty-response-text-and-body

Sub testlogin()

    fileUrl = "http://longurlwithparams"

    Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")

    WHTTP.Open "GET", fileUrl, False

    WHTTP.Send

    MsgBox WHTTP.Status
    MsgBox WHTTP.ResponseText
    MsgBox WHTTP.ResponseBody
    MsgBox WHTTP.GetAllResponseHeaders

    Set WHTTP = Nothing

End Sub


https://gist.github.com/refriedchicken/2885938
hmmmm

http://ramblings.mcpher.com/Home/excelquirks/json/rest/crest

hmmm
I have called a URL in excel and gotten the result ... WOOT
Option Explicit

Sub DoSomeJob()
Const sUrl As String = "http://randomnumbergenerator.intemodino.com/en/"

Dim oRequest As WinHttp.WinHttpRequest
Dim sResult As String

On Error GoTo Err_DoSomeJob

Set oRequest = New WinHttp.WinHttpRequest
With oRequest
    .Open "GET", sUrl, True
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
    .Send "{range:9129370}"
    .WaitForResponse
    sResult = .ResponseText
    Debug.Print sResult
    sResult = oRequest.Status
    Debug.Print sResult
End With



Exit_DoSomeJob:
    On Error Resume Next
    Set oRequest = Nothing
    Exit Sub
   
Err_DoSomeJob:
    MsgBox Err.Description, vbExclamation, Err.Number
    Resume Exit_DoSomeJob

End Sub

No comments:

Post a Comment