Hab dann hier auch noch eine Lösung in Script ( mit API ).
Hier kann man auch recht eindrucksvoll sehen, wie einfach man das in Java lösen kann und welche Klimmzüge man machen muß, um eine Lösung in Script hinzubekommen.
Zwar kann ich bei meiner Lösung noch ein paar Informationen mehr auslesen, da ich mir den responseHeader von der URL hole. Trotzdem fehlt hier noch die komplette Logig, um erst einmal an das zu prüfende Dokument ranzukommen.
Zudem muß dann noch die zu testende URL aufbereitet werden, um an die Funktion übergeben werden zu können. ( Kann man mit Sicherheit noch vereinfachen )
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_SERVICE_HTTP = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const INTERNET_DEFAULT_HTTP_PORT = 80
Const HTTP_QUERY_RAW_HEADERS_CRLF = 22
Declare Function W32_InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (Byval sAgent As String, Byval lAccessType As Long, Byval sProxyName As String, Byval sProxyBypass As String, Byval lFlags As Long) As Long
Declare Function W32_InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (Byval hInternetSession As Long, Byval sServerName As String, Byval nServerPort As Integer, Byval sUsername As String, Byval sPassword As String, Byval lService As Long, Byval lFlags As Long, Byval lContext As Long) As Long
Declare Function W32_InternetCloseHandle Lib "wininet.dll" Alias "InternetCloseHandle" (Byval hInet As Long) As Integer
Declare Function W32_HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" (Byval hHttpSession As Long, Byval sVerb As String, Byval sObjectName As String, Byval sVersion As String, Byval sReferer As String, Byval something As Long, Byval lFlags As Long, Byval lContext As Long) As Long
Declare Function W32_HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (Byval hHttpRequest As Long, Byval sHeaders As String, Byval lHeadersLength As Long, sOptional As Any, Byval lOptionalLength As Long) As Integer
Declare Function W32_HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (Byval hHttpRequest As Long, Byval lInfoLevel As Long, Byval sBuffer As String, lBufferLength As Long, lIndex As Long) As Integer
Function getResponseHeaders(sHost As String, sObject As String, sUserName As String, sPassword As String) As String
Dim rc%
Dim hSession&, hRequest&, hConnection&, cbHeaderBuf&
Dim headerBuf$
' initialize the WinInet API, retrieving any proxy or direct configuration info from the registry
hSession& = W32_InternetOpen("Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0)
If hSession& = 0 Then
Msgbox "Can't initialize Win32 Internet Functions (wininet.dll)", 16, "WinInet Error"
Else
' open an HTTP session for the site
hConnection& = W32_InternetConnect(hSession&, sHost, INTERNET_DEFAULT_HTTP_PORT, sUserName, sPassword, INTERNET_SERVICE_HTTP, 0, 0)
If hConnection& = 0 Then
Msgbox "Could not open HTTP session for site " & sHost, 16, "WinInet Error"
Else
' create a new HTTP request handle that will retrieve a resource from the server and not cache;
' note that you can also pass a POST request to upload info (see MS doc), or send an HTTP/1.0 request instead.
hRequest& = W32_HttpOpenRequest(hConnection&, "GET", sObject, "HTTP/1.1", 0, 0, INTERNET_FLAG_RELOAD, 0)
If hRequest& = 0 Then
Msgbox "Could not generate an HTTP request handle", 16, "WinInet Error"
Else
' send the request to the server with no additional headers (see MS doc to add your own headers)
rc%=W32_HttpSendRequest(hRequest&, "", 0, 0, 0)
If rc%=False Then
Msgbox "Could not send HTTP request", 16, "WinInet Error"
Else
' prepare a buffer for the response headers, then query 'em
headerBuf$=Space$(1024)
cbHeaderBuf&=Len(headerBuf$)
rc%=W32_HttpQueryInfo(hRequest&, HTTP_QUERY_RAW_HEADERS_CRLF, headerBuf$, cbHeaderBuf&, 0)
If rc% = 0 Then
Msgbox "Could not retrieve HTTP response headers", 16, "WinInet Error"
Else
' return the response headers on success
getResponseHeaders=Trim$(Left$(headerBuf$, cbHeaderBuf&))
End If
End If
End If
End If
End If
' close all handles
W32_InternetCloseHandle hRequest&
W32_InternetCloseHandle hSession&
W32_InternetCloseHandle hConnection&
End Function
Sub Click(Source As Button)
Dim sHeaders$, sHost$, sObject$
sHost$="
www.google.de"
sObject$="search?q=eknori&hl=de&ie=UTF-8&oe=UTF-8"
sHeaders$=getResponseHeaders(sHost$, sObject$, "", "")
Msgbox "The HTTP response headers from " & sHost$ & " are: " _
& Chr(13) & Chr(10) & Chr(13) & Chr(10) _
& sHeaders$, 0, "HTTP Response Headers"
If Instr(sHeaders$,"200 OK") Then
Msgbox "URL OK"
Else
Msgbox "URL NICHT OK"
End If
End Sub