AcidicChip Posted November 17, 2005 Share Posted November 17, 2005 (edited) Hi all. I'm trying to get the headers from a URL, to determine if it is an html page, audio file, video file, etc via 'File-type' header, and even knowing the file size via 'Content-length' (Even though for that I can use InetGetSize). rather than relying on the path/file extention (if any) of the URL. Am I able to do this? If so; How? Thanks in advance. Edited November 17, 2005 by AcidicChip Link to comment Share on other sites More sharing options...
AcidicChip Posted November 18, 2005 Author Share Posted November 18, 2005 How about a way to connect to a port 80, and retreive the headers that way? Link to comment Share on other sites More sharing options...
CatchFish Posted November 18, 2005 Share Posted November 18, 2005 HttpQueryInfo() function in wininet.dll would help. InternetOpen() & InternetOpenUrl() must be called before that. You can find an example in C:\Program Files\AutoIt3\include\Inet.au3. Also you may need documentation from MSDN... Link to comment Share on other sites More sharing options...
Luffy Posted November 18, 2005 Share Posted November 18, 2005 $WinHttpReq = ObjCreate("winhttp.winhttprequest.5.1") $WinHttpReq.open("GET",$URL) $WinHttpReq.send() $header = $WinHttpReq.GetAllResponseHeaders to get it all or for ex. $header = $WinHttpReq.GetResponseHeader("Content-length") seems easy enough for me Link to comment Share on other sites More sharing options...
AcidicChip Posted November 19, 2005 Author Share Posted November 19, 2005 Thanks for your help! Link to comment Share on other sites More sharing options...
AcidicChip Posted November 19, 2005 Author Share Posted November 19, 2005 Is there a way to do threading? To get the "content-type" it seems to take a bit. Is there a faster way to retreive it? Or maybe do some sort of threading? Link to comment Share on other sites More sharing options...
AcidicChip Posted November 19, 2005 Author Share Posted November 19, 2005 (edited) Okay, I thought of a faster way to get the content type, however, when using it repeatedly, it hangs the script, and even appears to hang my computer's internet. TCPStartup() Func GetContentType($url) $pre = StringMid($url, 1, StringInStr($url, "://")) & "//" $temp = StringSplit($url, "/") $host = $temp[3] $path = StringMid($url, StringLen($pre & $host) + 1) $sock = TCPConnect(TCPNameToIP($host), 80) $req = "GET " & $path & " HTTP/1.0" & @CRLF & "Host:" & $host & @CRLF & @CRLF $data = TCPSend($sock, $req) While 1 $recv = TCPRecv($sock, 1024) If StringLen($recv) Then ExitLoop EndIf Wend $temp = StringMid($recv, StringInStr($recv, "content-type: ") + 14) $temp = StringMid($temp, 1, StringInStr($temp, @CR) - 1) Return $temp EndFunc While 1 MsgBox(0, "", GetContentType("http://www.hiddensoft.com/")) Wend Before the loop hits 20 times, it'll freeze... Any idea why? Edited November 19, 2005 by AcidicChip Link to comment Share on other sites More sharing options...
Luffy Posted November 21, 2005 Share Posted November 21, 2005 works fine, no freeze at all Link to comment Share on other sites More sharing options...
AcidicChip Posted November 22, 2005 Author Share Posted November 22, 2005 works fine, no freeze at allThat's interresting. On my computer it freezes on the 17th/18th time and kills my internet connection, and on my wife's computer, I did it up to 50 times (Got bored hitting 'OK') with no problems. I wonder why that is.I'm going to load up a Virtual Machine and try it on there, and install software on it, to see what the problem is. Anyone else having this problem and/or know why? Link to comment Share on other sites More sharing options...
AcidicChip Posted November 22, 2005 Author Share Posted November 22, 2005 On my virtual machine, I have installed the same exact windows, anti-virus, updates, autoit, and web browsers. So, it's none of them. I'll test it on my computer at work tomorrow, I have the same software installed on that computer, as I do on mine. If it doesn't freeze there, then it's mostlikely some network setting on my computer or router. Link to comment Share on other sites More sharing options...
foggw Posted November 18, 2006 Share Posted November 18, 2006 I hope nobody minds me re-opening an almost year old-dead thread. I was trying to get HTTP header information (last-modified date) with as little overhead as possible when I stumbled upon this thread. $WinHttpReq = ObjCreate("winhttp.winhttprequest.5.1") $WinHttpReq.open("GET",$URL) $WinHttpReq.send() $header = $WinHttpReq.GetAllResponseHeaders to get it all` or for ex. $header = $WinHttpReq.GetResponseHeader("Content-length") seems easy enough for me Both @Luffy and @AcidicChip noted that sometimes the system would seem to hang. The problem is the HTTP Request Verb being used is GET. You are asking the server to send you the entire contents of the url. Solution: just change the request verb from GET to HEAD (just send the header information) $WinHttpReq = ObjCreate("winhttp.winhttprequest.5.1") $WinHttpReq.open("HEAD",$URL) $WinHttpReq.send() $header = $WinHttpReq.GetAllResponseHeaders ;should always work Using GetAllResponseHeaders should always work (providing the host can be contacted). Attempting to get a specific piece of information that is not available will fail. Bill Link to comment Share on other sites More sharing options...
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