Jump to content

How to ping long URL not just the root path


Recommended Posts

Pinging works fine for this short URL:

Local $var = Ping("www.ibiblio.org", 250)
If $var Then; also possible:  If @error = 0 Then ...
  MsgBox(0, "Status", "Online, roundtrip was:" & $var)
Else
  MsgBox(0, "Status", "An error occured with number: " & @error)
EndIf

But not for that:

Local $var = Ping("www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/", 250)
If $var Then; also possible:  If @error = 0 Then ...
  MsgBox(0, "Status", "Online, roundtrip was:" & $var)
Else
  MsgBox(0, "Status", "An error occured with number: " & @error)
EndIf

Is it possible to ping full path to directories?

Thanks

Link to comment
Share on other sites

No, you can't ping a folder, you have to ping the server, which is the part between the // and the / in the URL.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks brewman, is there any function to check if the long URL/folders are online or if the URL is valid or not?

I used this code but not error pops up with unvalid URL.

#include <IE.au3>
$oIE = _IECreate("www.autoitscriptnoexist.com/nonexistantfolder", 0)

How to check if a long path URL is valid?

Edited by xuzo
Link to comment
Share on other sites

Thanks brewman, is there any function to check if the long URL/folders are online or if the URL is valid or not?

I used this code but not error pops up with unvalid URL.

#include <IE.au3>
$oIE = _IECreate("www.autoitscriptnoexist.com/nonexistantfolder", 0)

How to check if a long path URL is valid?

What you are asking is not possible; servers and resources simply do not work that way.

PING is to determine the packet loss and speed of a server. An example of a server is autoitscript.com or ibiblio.org.

Trying to ping ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/ is not valid.

What you are trying to do, rather, is determine if a resource on a server is accessible. You are not trying to determine if the server itself is reachable thus using ping is not valid.

Instead, you should make a request to the server for the URL ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/ or whatever. It will return a 200 OK message (lookup HTML headers if you do not know what that means) if the resource is available. Anything else is a special-case or error, and depends on the code. For example, a 404 indicates the resource does not exist.

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

I would first do a Ping to check if the server is up and running and then do a

$iSize = InetGetSize("URL", 1)
This returns just the size of the html page and doesn't transfer the whole content. If it doesn't exist @error is set.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you to all you guys for the expert advice, but still no clue!....

I tried this:

#include <IE.au3>
$oIE = _IECreate("www.autoitscriptnoexist.com/nonexistantfolder", 0)
$iSize = InetGetSize("www.autoitscriptnoexist.com/nonexistantfolder", 1)

I'm aware of 404, 503 and 500 errors but don't know how to make AutoIT "read the error", I have yet to learn how to do an if command that can read:

"if the text on the page says 404" then do "this"

I'm trying to find a way for the sript to tell me if the page is online or not, if the URL exists or not. And then choose the next step in the script.

Edited by xuzo
Link to comment
Share on other sites

Error codes 404 etc. are HTTP error codes. To retrieve this codes you need to use the written by trancexx.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you guys!

Ok sounds good, but how could I do this:

Instead, you should make a request to the server for the URL ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/ or whatever. It will return a 200 OK message (lookup HTML headers if you do not know what that means) if the resource is available. Anything else is a special-case or error, and depends on the code. For example, a 404 indicates the resource does not exist.

What is the code to do this:

"request to the server for the URL"

Edited by xuzo
Link to comment
Share on other sites

Sorry, haven't done it myself. I fear you will have to dig through the thread and search for the HTTP requests you need to send yourself.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

How about looking for text on the page, if the text is there, it's ok, if the text isn't there stop or do something else?

In my particular task the text:

"Index of ftp://ibiblio.org"

is on all the pages that are online, if that text is not on the page means the page is down.

So how could I set up:

1. Go to URL

2. Check on the page to see if "Index of ftp://ibiblio.org" is there

3. If the text is diplayed do nothing and move to next step

4. If text is not there pop up an error message

I'm starting to get a grasp on if commands but not sure how to fetch the text on an HTML document either from visible view or source code.

Thanks

Edited by xuzo
Link to comment
Share on other sites

You can try using this.

#include "WinHttp.au3"

Global $hWINHTTP_STATUS_CALLBACK = DllCallbackRegister("__WINHTTP_STATUS_CALLBACK", "none", "handle;dword_ptr;dword;ptr;dword")

Global $Return = _GetPage("http://www.google.com/")
Switch @error
    Case 0
        ConsoleWrite("Html:" & $Return & @CR)
        ; here is where you can check for a string
    Case Else
        ConsoleWrite(@error&@CR)
EndSwitch


Func _GetPage($Page)

    If Not $Page Then Return SetError(1, 0, 0)
    Local $Crack = _WinHttpCrackUrl($Page)
    If @error Then
        Return SetError(2, 0, 0)
    EndIf

    Local $Port = $INTERNET_DEFAULT_PORT

    If Not $Crack[0] Then $Crack[0] = "http"

    If StringLower($Crack[0]) == "http" Then $Port = $INTERNET_DEFAULT_HTTP_PORT
    If StringLower($Crack[0]) == "https" Then $Port = $INTERNET_DEFAULT_HTTPS_PORT

    ConsoleWrite("Target set: " & $Crack[0]&"://"&$Crack[2]&$Crack[6]&$Crack[7]&@CR)

    Local $hWnd = _WinHttpOpen("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")
    If @error Then Return SetError(3, 0, 0)

    ;_WinHttpSetTimeouts($hWnd, 0, 5000, 5000, 2500)

    _WinHttpSetStatusCallback($hWnd, $hWINHTTP_STATUS_CALLBACK)

    Local $hConnect = _WinHttpConnect($hWnd, $Crack[2], $Port)
    If @error Then
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hWnd)
        Return SetError(4, 0, 0)
    EndIf

    Local $hRequest = _WinHttpOpenRequest($hConnect, "GET", $Crack[6], Default, $Crack[0]&"://"&$Crack[2]&$Crack[6]&$Crack[7])
    If Not $hRequest Then
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hWnd)
        Return SetError(5, 0, 0)
    EndIf

    _WinHttpSendRequest($hRequest, "", "")
    If @error Then
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hWnd)
        Return SetError(6, 0, 0)
    EndIf

    _WinHttpReceiveResponse($hRequest)
    If @error Then
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hWnd)
        Return SetError(7, 0, 0)
    EndIf

    Local $Data
    If _WinHttpQueryDataAvailable($hRequest) Then
        Do
            $Data &= _WinHttpReadData($hRequest, 0)
        Until @error
    Else
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hWnd)
        Return SetError(8, 0, 0)
    EndIf

    _WinHttpCloseHandle($hWnd)
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    Return SetError(0, 0, $Data)
EndFunc

Func __WINHTTP_STATUS_CALLBACK($hInternet, $iContext, $iInternetStatus, $pStatusInformation, $iStatusInformationLength)
    #forceref $hInternet, $iContext, $pStatusInformation, $iStatusInformationLength
    ; Interpret the status
    Local $sStatus
    Switch $iInternetStatus
        Case $WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION
            $sStatus = "Closing the connection to the server"
        Case $WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
            $sStatus = "Successfully connected to the server"
        Case $WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
            $sStatus = "Connecting to the server."
        Case $WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED
            $sStatus = "Successfully closed the connection to the server"
        Case $WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE
            $sStatus = "Data is available to be retrieved with WinHttpReadData"
        Case $WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
            $sStatus = "An HINTERNET handle has been created: " & $hInternet
        Case $WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
            $sStatus = "This handle value has been terminated: " & $hInternet
        Case $WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
            $sStatus = "The response header has been received and is available with WinHttpQueryHeaders"
        Case $WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE
            $sStatus = "Received an intermediate (100 level) status code message from the server"
        Case $WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
            $sStatus = "Successfully found the IP address of the server"
        Case $WINHTTP_CALLBACK_STATUS_READ_COMPLETE
            $sStatus = "Data was successfully read from the server"
        Case $WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
            $sStatus = "Waiting for the server to respond to a request"
        Case $WINHTTP_CALLBACK_STATUS_REDIRECT
            $sStatus = "An HTTP request is about to automatically redirect the request"
        Case $WINHTTP_CALLBACK_STATUS_REQUEST_ERROR
            $sStatus = "An error occurred while sending an HTTP request"
        Case $WINHTTP_CALLBACK_STATUS_REQUEST_SENT
            $sStatus = "Successfully sent the information request to the server"
        Case $WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
            $sStatus = "Looking up the IP address of a server name"
        Case $WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
            $sStatus = "Successfully received a response from the server"
        Case $WINHTTP_CALLBACK_STATUS_SECURE_FAILURE
            $sStatus = "One or more errors were encountered while retrieving a Secure Sockets Layer (SSL) certificate from the server"
        Case $WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
            $sStatus = "Sending the information request to the server"
        Case $WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE
            $sStatus = "The request completed successfully"
        Case $WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE
            $sStatus = "Data was successfully written to the server"
    EndSwitch
    ; Print it
    ConsoleWrite(">" & $sStatus & @CRLF)
EndFunc    ;==>__WINHTTP_STATUS_CALLBACK
Link to comment
Share on other sites

$s_Src = BinaryToString((InetRead("somesite"))
If StringInStr($s_Src, "Index of ftp://ibiblio.org") Then
    ;; Good to go
Else
    ;; Houston we have a problem.
EndIf

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi Geo,

I think this is nearly perfect but for some reason I get some errors when running, am I missing something? Is there some extra code I need to put on top of what you gave me? Maybe an include?

$s_Src = BinaryToString((InetRead("www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/"))
If StringInStr($s_Src, "Index of") Then
;; Good to go
MsgBox(0, "Is text there?", "yes text is there")
Else
;; Houston we have a problem.
MsgBox(0, "Is text there?", "no, text isn't there")
EndIf

Here are the errors from console:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:xtra-dfAutoITexamples_brunofind-text-on-page.au3" /UserParams

+>13:06:33 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X64 OS:X86)

>Running AU3Check (1.54.22.0) from:C:Program FilesAutoIt3

D:xtra-dfAutoITexamples_brunofind-text-on-page.au3(1,107) : ERROR: syntax error

$s_Src = BinaryToString((InetRead("www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/"))

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:xtra-dfAutoITexamples_brunofind-text-on-page.au3(2,36) : ERROR: syntax error

If StringInStr($s_Src, "Index of") Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:xtra-dfAutoITexamples_brunofind-text-on-page.au3(5,1) : ERROR: syntax error

Else

^

D:xtra-dfAutoITexamples_brunofind-text-on-page.au3 - 3 error(s), 0 warning(s)

!>13:06:33 AU3Check ended. Press F4 to jump to next error.rc:2

>Exit code: 0 Time: 0.405

Edited by xuzo
Link to comment
Share on other sites

$s_Src = BinaryToString(InetRead(www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/))

Extra parenthesis removed

Note that the forum is dropping the quotes around the URL so make sure you put them in.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi Geo,

Thank you so much for everybody for the help by the way!

....but still not working...! ;(

Here is the code raw since the forum seems to strip things:

$s_Src = BinaryToString(InetRead("www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/"))

If StringInStr($s_Src, "Index of") Then

;; Good to go

MsgBox(0, "Is text there?", "yes text is there")

Else

;; Houston we have a problem.

MsgBox(0, "Is text there?", "no, text isn't there")

EndIf

Even if the text "Index of" shows up on the page, my message box still says it's not there!

Link to comment
Share on other sites

Ooops. My bfault

For some reason I just noticed that the rest of your URL is missing.

You need everything including the page. Like default.htm or whatever.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi Geo,

Just noticed you are from Vancouver Island! I used to do a lot of jobs from Vancouver to Nanaimo, nice jobs also with the long feery rides! ;) I live in Thailland now but sometimes miss Canada...!

But anyways...the URL has no extension because it's a folder...there HAS to be a way to do this...I hope...!

All I want to do is check if a page is online, if it is keep doing something, if not move to something else....

Cheers!

Edited by xuzo
Link to comment
Share on other sites

Have you even tried the code I gave you?

#include "WinHttp.au3"

Global $hWINHTTP_STATUS_CALLBACK = DllCallbackRegister("__WINHTTP_STATUS_CALLBACK", "none", "handle;dword_ptr;dword;ptr;dword")

Global $Return = _GetPage("http://www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/")
Switch @error
Case 0
ConsoleWrite("+>Html Returned: " & $Return & @CR)
; here is where you can check for a string
Case Else
ConsoleWrite("!>Error:" & @error & @CR)
EndSwitch


Func _GetPage($Page)

If Not $Page Then Return SetError(1, 0, 0)
Local $Crack = _WinHttpCrackUrl($Page)
If @error Then
Return SetError(2, 0, 0)
EndIf

Local $Port = $INTERNET_DEFAULT_PORT

If Not $Crack[0] Then $Crack[0] = "http"

If StringLower($Crack[0]) == "http" Then $Port = $INTERNET_DEFAULT_HTTP_PORT
If StringLower($Crack[0]) == "https" Then $Port = $INTERNET_DEFAULT_HTTPS_PORT

ConsoleWrite("Target set: " & $Crack[0]&"://"&$Crack[2]&$Crack[6]&$Crack[7]&@CR)

Local $hWnd = _WinHttpOpen("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")
If @error Then Return SetError(3, 0, 0)

;_WinHttpSetTimeouts($hWnd, 0, 5000, 5000, 2500)

_WinHttpSetStatusCallback($hWnd, $hWINHTTP_STATUS_CALLBACK)

Local $hConnect = _WinHttpConnect($hWnd, $Crack[2], $Port)
If @error Then
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hWnd)
Return SetError(4, 0, 0)
EndIf

Local $hRequest = _WinHttpOpenRequest($hConnect, "GET", $Crack[6], Default, $Crack[0]&"://"&$Crack[2]&$Crack[6]&$Crack[7])
If Not $hRequest Then
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hWnd)
Return SetError(5, 0, 0)
EndIf

_WinHttpSendRequest($hRequest, "", "")
If @error Then
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hWnd)
Return SetError(6, 0, 0)
EndIf

_WinHttpReceiveResponse($hRequest)
If @error Then
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hWnd)
Return SetError(7, 0, 0)
EndIf

Local $Data
If _WinHttpQueryDataAvailable($hRequest) Then
Do
$Data &= _WinHttpReadData($hRequest, 0)
Until @error
Else
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hWnd)
Return SetError(8, 0, 0)
EndIf

_WinHttpCloseHandle($hWnd)
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
Return SetError(0, 0, $Data)
EndFunc

Func __WINHTTP_STATUS_CALLBACK($hInternet, $iContext, $iInternetStatus, $pStatusInformation, $iStatusInformationLength)
#forceref $hInternet, $iContext, $pStatusInformation, $iStatusInformationLength
; Interpret the status
Local $sStatus
Switch $iInternetStatus
Case $WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION
$sStatus = "Closing the connection to the server"
Case $WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
$sStatus = "Successfully connected to the server"
Case $WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
$sStatus = "Connecting to the server."
Case $WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED
$sStatus = "Successfully closed the connection to the server"
Case $WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE
$sStatus = "Data is available to be retrieved with WinHttpReadData"
Case $WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
$sStatus = "An HINTERNET handle has been created: " & $hInternet
Case $WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
$sStatus = "This handle value has been terminated: " & $hInternet
Case $WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
$sStatus = "The response header has been received and is available with WinHttpQueryHeaders"
Case $WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE
$sStatus = "Received an intermediate (100 level) status code message from the server"
Case $WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
$sStatus = "Successfully found the IP address of the server"
Case $WINHTTP_CALLBACK_STATUS_READ_COMPLETE
$sStatus = "Data was successfully read from the server"
Case $WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
$sStatus = "Waiting for the server to respond to a request"
Case $WINHTTP_CALLBACK_STATUS_REDIRECT
$sStatus = "An HTTP request is about to automatically redirect the request"
Case $WINHTTP_CALLBACK_STATUS_REQUEST_ERROR
$sStatus = "An error occurred while sending an HTTP request"
Case $WINHTTP_CALLBACK_STATUS_REQUEST_SENT
$sStatus = "Successfully sent the information request to the server"
Case $WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
$sStatus = "Looking up the IP address of a server name"
Case $WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
$sStatus = "Successfully received a response from the server"
Case $WINHTTP_CALLBACK_STATUS_SECURE_FAILURE
$sStatus = "One or more errors were encountered while retrieving a Secure Sockets Layer (SSL) certificate from the server"
Case $WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
$sStatus = "Sending the information request to the server"
Case $WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE
$sStatus = "The request completed successfully"
Case $WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE
$sStatus = "Data was successfully written to the server"
EndSwitch
; Print it
ConsoleWrite(">" & $sStatus & @CRLF)
EndFunc ;==>__WINHTTP_STATUS_CALLBACK

It works, and so does the example geo posted, you just need to add the scheme name.

$s_Src = BinaryToString(InetRead("http://www.ibiblio.org/pub/multimedia/mutopia/BachJS/BWV16/Cantata_16_no_5/"))
If StringInStr($s_Src, "Index of") Then
    ;; Good to go
    MsgBox(0, "Is text there?", "yes text is there")
Else
    ;; Houston we have a problem.
    MsgBox(0, "Is text there?", "no, text isn't there")
EndIf
Link to comment
Share on other sites

Hi

Yes I does work now! Bingo!

I got the revised code from Geo (that you posted on top) working, what does "add the scheme name" mean? Whatever you did to the code it works now! ;)

Thanks,

Edited by xuzo
Link to comment
Share on other sites

Hi guys,

This is soooooooo cool that I got it working that I figured I might as well push my luck a little!

Trying to make it work with a text file now:

$s_Src = BinaryToString ShellExecute("notepad.exe", @ScriptDir & "text.txt", "", "OPEN")
If StringInStr($s_Src, "this is text") Then
; Good to go
MsgBox(0, "Is text there?", "yes text is there")
Else
; Houston we have a problem.
MsgBox(0, "Is text there?", "no, text isn't there")
EndIf

Of course I'm doing something wrong as usual....!

Edited by xuzo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...