Dashboard > Public Content > ... > ExcelVBA > Get or Post to a URL
  Public Content Log In   View a printable version of the current page.  
  Get or Post to a URL
Added by James Richardson, last edited by James Richardson on Jun 28, 2006
Labels: 
(None)

Function sendRequest(url As String, Optional method As String = "POST", Optional data As String = "", Optional timeoutSeconds As Long = 60, Optional contentType As String = "application/x-www-form-urlencoded", Optional username As String = "", Optional password As String = "") As serverxmlhttp 
 
    Dim iAmHappy As Boolean 
    iAmHappy = True 
 
    Dim httpRequest As New serverxmlhttp 
 
    ' resolve, connect, send, receive timeouts all in ms 
    httpRequest.setTimeouts 500, 2000, 2000, timeoutSeconds * 1000 
     
    If (username = "") Then 
        httpRequest.Open method, url, True 
    Else 
        httpRequest.Open method, url, True, username, password 
    End If 
    httpRequest.setRequestHeader "Connection", "close" 
    httpRequest.setRequestHeader "Content-Type", contentType 
 
    If (data = "") Then 
        httpRequest.send 
    Else 
        httpRequest.send data 
    End If 
 
    On Error GoTo SomeError 
    httpRequest.waitForResponse timeoutSeconds 
 
 
    Set sendRequest = httpRequest 
    Exit Function 
SomeError: 
    On Error GoTo 0
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators