Reputation: 31
Checking some URLs with
Function SiteStatus(ByVal URL As String, SiteStatusText As String) As Long
Dim oHttp As New WinHttp.WinHttpRequest
oHttp.Option(WinHttpRequestOption_EnableRedirects) = False
oHttp.Open "GET", URL, False
oHttp.Send
SiteStatus = oHttp.Status
SiteStatusText = oHttp.StatusText
End Function
generally works fine. Only a few URLs throw a VBA error -2147012744. The Server is giving an invalid or unknown response. Some URLs in real work, I can open them with SHDocVw library, and some not, - that makes no difference. for instance:
http: //s2.excoboard.com/Courthouse_Steps_Mavens/150601/1831324
or
http: //www.geld-und-leben.com/anleitung/
or
http: //globalnews.ca/news/3025046/justin-timberlakes-illegal-voting-booth-selfie-is-under-review/
I wanna check the status of these sites although. How? What's the point?
Upvotes: 0
Views: 1992
Reputation: 2278
i know that this is old, but here is some VBA code that works.
some of the values for oHttp.Option came from http://www.808.dk/?code-simplewinhttprequest
Sub test()
' add reference to Microsoft WinHTTP Services
Dim URL As String
URL = "http://globalnews.ca/news/3025046/justin-timberlakes-illegal-voting-booth-selfie-is-under-review"
Dim oHttp As WinHttpRequest
Set oHttp = New WinHttpRequest
oHttp.Open "GET", URL, False
oHttp.Option(WinHttpRequestOption_UserAgentString) = "http_requester/0.1"
oHttp.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300 ' ignore all err, 0: accept no err
oHttp.Option(WinHttpRequestOption_EnableRedirects) = True
oHttp.Option(WinHttpRequestOption_EnableHttpsToHttpRedirects) = True
oHttp.send
Do While True
DoEvents
If oHttp.Status Then Exit Do
Loop
Debug.Print oHttp.Status
End Sub
Upvotes: 2