WebRequest
Executes a webrequest and returns the content.
Syntax
WebRequest( URL )
Parameters
Name |
Type |
Description |
URL |
String |
Required. The complete url of the webrequest. |
Return value
String : The content the url provides. When an error occurs an empty string is returned.
Code
Public Function WebRequest(ByVal URL As String) As String
On Error GoTo WebRequest_Error
Dim oXHTTP As Object
' Prevent caching, add a time depended parameter
If InStr(1, URL, "?", 1) <> 0 Then
URL = URL & "&cb=" & Timer() * 100
Else
URL = URL & "?cb=" & Timer() * 100
End If
'
' Create object to XMLHTTP object (late binding)
'
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "GET", URL, False
oXHTTP.Send
WebRequest = oXHTTP.responseText
Set oXHTTP = Nothing
WebRequest_Exit:
On Error Resume Next
Exit Function
WebRequest_Error:
WebRequest = ""
Resume WebRequest_Exit
End Function
Internettag:Internet
Remarks
- This code is very straight forward. It does not provide any error handling, but when the call fails just an empty string will be returned.