Kyan Posted November 7, 2014 Share Posted November 7, 2014 (edited) Hi, never tried to download files besides html with winhttp Does anyone know what I'm doing wrong here? expandcollapse popup#include <WinHttp.au3> #NoTrayIcon ;$baseURL = "http://cdn0.iconfinder.com/data/icons/iconsweets2/40/penguin_linux_tux.png" $pURL = "/data/icons/iconsweets2/40/penguin_linux_tux.png" $dlp = _Get($pURL) ConsoleWrite(@LF&"##Output in binary:"&IsBinary($dlp[1])&@LF&@LF) Exit Func _Get($pagin) ; [0]header, [1]data Local $sRetur[2] = ['', ''] If 1 Then $gOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.27 Safari/537.36") $gConnect = _WinHttpConnect($gOpen, "cdn0.iconfinder.com") $gRequest = _WinHttpOpenRequest($gConnect, "GET", $pagin, 'HTTP/1.1') ;If Not $rData Then _WinHttpSetOption($gRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) _WinHttpAddRequestHeaders($gRequest, "Host: cdn0.iconfinder.com") _WinHttpAddRequestHeaders($gRequest, "Connection: keep-alive") _WinHttpAddRequestHeaders($gRequest, "Accept: application/json, text/javascript, image/png;q=0.8, */*; q=0.02") _WinHttpAddRequestHeaders($gRequest, "Accept-Language:en-US;q=0.8,en;q=0.4") _WinHttpAddRequestHeaders($gRequest, "Accept-Encoding: */q=0") _WinHttpSendRequest($gRequest) _WinHttpReceiveResponse($gRequest) If _WinHttpQueryDataAvailable($gRequest) Then $sRetur[0] = _WinHttpQueryHeaders($gRequest) While 1 $chunk = _WinHttpReadData($gRequest,2) If @error Then ExitLoop $sRetur[1] &= _WinHttpSimpleBinaryConcat($sRetur[1],$chunk) Sleep(20) WEnd Else $sRetur[0] = '' $sRetur[1] = '' EndIf _WinHttpCloseHandle($gRequest) _WinHttpCloseHandle($gConnect) _WinHttpCloseHandle($gOpen) EndIf Return $sRetur EndFunc ;==>_Get IsBinary($dlp[1]) is outputing "0" everytime, I specified _WinHttpReadData() to read as binary, and I use _WinHttpSimpleBinaryConcat() to concatenate binary that, don't know what is failing here Hope someone here knows where I'm failing :| EDIT: I wrote the data to a file and the picture is intact: $fi = FileOpen(@DesktopDir&"\te.png",2+16) FileWrite($fi,$dlp[1]) FileClose($fi) It needs to be binary for further use with Load_BMP_From_Mem($dlp[1],True) Edited November 7, 2014 by Kyan Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
Solution Kyan Posted November 8, 2014 Author Solution Share Posted November 8, 2014 Solved, just Binary($dlp[1]) and is recognized by GDI as a binary image Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better 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