Jump to content

Getting Response status code of any site


UNO
 Share

Recommended Posts

I need to get the response status code when I enter a URL name.

For example www.yahoo.com or any secure site i.e https

Following is my script(almost the same as the example)

#include <HTTP.au3>

$host = "www.yahoo.com"

$page = "/overload/autoit/getpage.php"

;ConsoleWrite("Example GET Request:"&@CRLF)

$socket = _HTTPConnect($host)

;ConsoleWrite("Socket Created: "&$socket&@CRLF)

$get = _HTTPGet($host, $page, $socket)

;ConsoleWrite("Bytes sent: "&$get&@CRLF)

$recv = _HTTPRead($socket,1)

If @error Then

;ConsoleWrite("_HTTPRead Error: "&@error&@CRLF)

;ConsoleWrite("_HTTPRead Return Value: "&$recv &@CRLF)

Msgbox(0,"HTTP Return Code: ",$recv&@CRLF)

Else

Msgbox(0,"HTTP Return Code: ",$recv[0]&@CRLF)

;ConsoleWrite("HTTP Return Code: "&$recv[0]&@CRLF)

;ConsoleWrite("HTTP Return Response: "&$recv[1]&@CRLF)

;ConsoleWrite("Number of headers: "&UBound($recv[3])&@CRLF)

;ConsoleWrite("Size of data downloaded: "&StringLen($recv[4])&" bytes"&@CRLF)

;ConsoleWrite("Page downloaded: "&@CRLF&$recv[4]&@CRLF)

EndIf

_HTTPClose($socket)

Also Consolewrite doesnt work in may case.so i am using Msgbox

Any guesses and help?Or am i using it wrong?

Thanks in advance

Link to comment
Share on other sites

Ehm... HTML udf? :whistle: lol

Global Const $Packet = "GET / HTTP/1.0" & @CRLF & @CRLF
;Global Const $Packet = "GET /overload/autoit/getpage.php HTTP/1.0" & @CRLF & @CRLF

TCPStartup()

Dim $URL = "www.yahoo.com"
Dim $IP = TCPNameToIP($URL)
ConsoleWrite($URL & " -> " & $IP & @CRLF)

Dim $Socket = TCPConnect($IP,80)

ConsoleWrite("Connection return: " & $Socket & " (-1 = error)" & @CRLF)

TCPSend($Socket,$Packet)

ConsoleWrite("Packet send: " & $Packet & @CRLF )

Dim $Data = ''
While 1
    $Data &= TCPRecv($Socket,1024)
    If @error Then ExitLoop
    ConsoleWrite($Data)
WEnd

ConsoleWrite(@CRLF & "Connection terminated." & @CRLF)

$Split = StringSplit($Data,@LF,1)
$ConnectionStatus = $Split[1]

MsgBox(0, "Connection status", $ConnectionStatus )

Edit: Kudos for the TCP functions.. :]

Edited by Manadar
Link to comment
Share on other sites

Hi Manadar,

Thanks for helping me but it didnt work out.See the image below.

Also how do I revamp it up for for https:// pages

I have no clue how https works.. I'm just an hobbyist.

http://en.wikipedia.org/wiki/Https#How_it_works

By the way, I've copied and paste the code that I put up on these forums, and without changing anything it works like expected and gives me 200 OK message. I do not see a reason why AutoIt would behave differently on your side..

Edit: This may work for you...

CODE
#include <Array.au3>

Global Const $Packet = "GET / HTTP/1.0" & @CRLF & @CRLF
;Global Const $Packet = "GET /overload/autoit/getpage.php HTTP/1.0" & @CRLF & @CRLF

TCPStartup()

Dim $URL = "www.yahoo.com"
Dim $IP = TCPNameToIP($URL)
ConsoleWrite($URL & " -> " & $IP & @CRLF)

Dim $Socket = TCPConnect($IP,80)

ConsoleWrite("Connection return: " & $Socket & " (-1 = error)" & @CRLF)

TCPSend($Socket,$Packet)

ConsoleWrite("Packet send: " & $Packet & @CRLF )

Dim $Data = ''
While 1
    $Data &= TCPRecv($Socket,1024)
    If @error Then ExitLoop
    ConsoleWrite($Data)
WEnd

ConsoleWrite(@CRLF & "Connection terminated." & @CRLF)

$Split = StringSplit($Data,@LF,1)
_ArrayDisplay($Split,"")
Edited by Manadar
Link to comment
Share on other sites

  • 2 weeks later...

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