Jump to content

Download Picture without InetGet


Recommended Posts

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
Link to comment
Share on other sites

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

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