UNO Posted March 30, 2007 Posted March 30, 2007 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
jvanegmond Posted March 30, 2007 Posted March 30, 2007 (edited) Ehm... HTML udf? lolGlobal 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 March 30, 2007 by Manadar github.com/jvanegmond
UNO Posted March 30, 2007 Author Posted March 30, 2007 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
jvanegmond Posted March 30, 2007 Posted March 30, 2007 (edited) 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:// pagesI 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 March 30, 2007 by Manadar github.com/jvanegmond
UNO Posted March 30, 2007 Author Posted March 30, 2007 still not working.Maybe i will replace consolewrite with msgbox. and the status code is displayed in arraydisplay?
jvanegmond Posted March 30, 2007 Posted March 30, 2007 (edited) What version of AutoIt are you using? Is that release or beta? Yes the status code, has to be somewhere in the MsgBox. Edited March 21, 2018 by jvanegmond github.com/jvanegmond
UNO Posted April 10, 2007 Author Posted April 10, 2007 I am using the release. The problem isnt resolved...
jvanegmond Posted April 10, 2007 Posted April 10, 2007 (edited) I am using the release.The problem isnt resolved... Get Beta... Edited April 10, 2007 by Manadar github.com/jvanegmond
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now