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