Jump to content

Recommended Posts

Posted (edited)

Hi!

I'm trying to download a Picture via HTTP without using InetGet, because I want to add headers later.

This is what I got so far:

#include <String.au3>
myGet("www.google.at", "/intl/de_at/images/logo.gif")

Func myGet($host, $file, $headers = "")
    Local $req
    Local $ip
    Local $ms
    Local $fp
    Local $recv

    $req = "GET " & $file & " HTTP/1.1" & @CRLF
    $req &= "Host: " & $host & @CRLF
    $req &= $headers
    $req &= @CRLF

    TCPStartup()
    $ip = TCPNameToIP($host)
    $ms = TCPConnect($ip, 80)
    TCPSend($ms, $req)
    Sleep(1000)
    $recv = TCPRecv($ms, 1000000)
    TCPCloseSocket($ms)
    
    $fp = FileOpen("logo.gif", 2)
    FileWrite($fp, TrimHeader($recv))
    FileClose($fp)
EndFunc   ;==>myGet

Func TrimHeader($str)
    Return StringMid($str, StringInStr($str, @CRLF & @CRLF) + StringLen(@CRLF & @CRLF))
EndFunc   ;==>TrimHeader

However, when I try to open logo.gif I get an error.

I looked into the File and there seems to be only hexadecimal characters (no, I don't use an hex-editor).

I tried _HexToString but it always returns -1.

I hope you can help me.

EDIT: added TCPCloseSocket($ms), still doesn't work.

Edited by Zonarius
Posted

$fp = FileOpen("logo.gif", 2+16);2 is over write and 16 is read/write in binary, 2+16=18 so overwrite in binary
    FileWrite($fp, TrimHeader($recv))
    FileClose($fp)
EndFunc  ;==>myGet

Func TrimHeader($str)
    Return StringMid($str, StringInStr($str, @CRLF & @CRLF) + StringLen(@CRLF & @CRLF))
EndFunc  ;==>TrimHeader

Trust me to make SkyNet with AutoIt...

Posted

Hi davecollinsnz!

I now tried your solution, but it still doesn't work.

It's the same as before, the file only contains hexadecimal characters.

Did you try it out and did it work for you?

Thank you anyway.

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
×
×
  • Create New...