-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhttpRequest.bas
More file actions
43 lines (33 loc) · 1.34 KB
/
httpRequest.bas
File metadata and controls
43 lines (33 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''''''''''''''''''''''''''''''''''''''''''''''
' Http Request '
'''''''''''''''''''''''''''''''''''''''''''''''
'recieves url as string, and post (ex. True or False) as boolean
'outputs the http resonse
'this function defaults to a GET request unless post boolean is true
Function httpRequest(url As String, Optional post as Boolean) As String
'dimension variables
Dim hReq As Object
Dim apiKeys as String: apiKeys = ""
Dim httpType as String: type = "GET"
'is the request to POST or GET
If post Then
httpType = "POST"
End If
'on error return ""
On Error GoTo httpRequestError
'create XML HTTP object
Set hReq = CreateObject("MSXML2.XMLHTTP")
'open request and assign headers
With hReq
.Open httpType, url, False
.SetRequestHeader "Authorization", "Basic " & common.Base64Encode(apiKeys)
.Send
End With
'return response
httpRequest = hReq.ResponseText
'garbage collection
Set hReq = Nothing
Exit Function
httpRequestError:
httpRequest = ""
End Function