Jump to content

Returning HTTP Response/Status Codes with AutoIt


Recommended Posts

Hello all,

I searched all over the place for example code that can return the HTTP Response/Status codes and couldn't find one anywhere. So.... I decided to write one myself. I hope a few others will find this helpful.

Dim $objhttp
Dim $httpstatus
Dim $CheckHTTPStatus
Dim $codetype
Dim $strURL = "http://www.autoitscript.com/"


CheckHttpStatus($strURL)
Func CheckHttpStatus($strActlURL)
    $objhttp = ObjCreate("MSXML2.XMLhttp.3.0") 
    $objhttp.Open("GET", $strActlURL, false) 

    $objhttp.Send 
    $httpstatus = $objhttp.Status
    If $httpstatus = "" Then
        $CheckHTTPStatus = "Error"
    Else
        $codetype = stringleft($httpstatus,1)
        If $codetype = 2 or $codetype = 3 Then
            $CheckHttpStatus = "Success"
        Else
            $CheckHttpStatus = "Error"
        EndIf
    EndIf
    
EndFunc

msgbox(0,"test",$httpstatus)

Cheers! SJones

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...