Jump to content

Download zip with WinInet


Recommended Posts

Hi,

I post some values etc. to a website so that I can download a zip-file.

The POST-header:

POST /d.x HTTP/1.1

Host: www.website.com

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.12) Gecko/20080201 Firefox

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: nl,en-us;q=0.8,en;q=0.5,de;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: http://www.website.com/d.x?N2mhVY9

Content-Type: application/x-www-form-urlencoded

Content-Length: 52

ID=N2mhVY9&down_load=Click+here+to+download+the+file

The response headers:

HTTP/1.x 200 OK

Date: Wed, 26 Mar 2008 01:53:39 GMT

Server: Apache/2.0.61 (Unix) PHP/5.2.2

X-Powered-By: PHP/5.2.2

content-disposition: filename=filename.zip

Content-Description: filename.zip

Content-Transfer-Encoding: binary

Pragma: no-cache

Expires: 0

Keep-Alive: timeout=15, max=100

Connection: Keep-Alive

Content-Type: application/zip; name=filename.zip

Content-Length: 231

If I go to or use InetGet for this location, it gives me a 404-error:

http://www.website.com/filename.zip

I tried to use the InternetRead function in wininet.dll, but it only gives me back the first 5 characters:

Func _InternetRead($l_Request)
    Global $ai_IRF, $s_Buf = ''
    Global $v_Struct = DllStructCreate('udword')
    DllStructSetData($v_Struct, 1, 1)
   
    While DllStructGetData($v_Struct, 1) <> 0
        $ai_IRF = DllCall($dll, 'int', 'InternetReadFile', 'long', $l_Request, 'str', '', 'int', 128, 'ptr', DllStructGetPtr($v_Struct))
        $s_Buf &= StringLeft($ai_IRF[2], DllStructGetData($v_Struct, 1))
    WEnd
    
    Return $s_Buf
EndFunc

First 5 bytes:

PK

Full 231 bytes:

PK gç6jªF W

serial.txtóKÌMµRðË/*ÉÏSpÌ+É,Ë,*-V0200 Ö÷³RËK*.°ó Ôus ×uvòðÖ

sñÐõ²ô

Óurò2Áª PK gç6jªF W

serial.txtPK 8 n + This file was downloaded from WWW.WEBSI.COM

According to HTTPSniffer OSS.exe (I compiled my source and named it OSS.exe) recieved the same amount of bytes as Firefox:

525+231 bytes

231 bytes is the size op the zip-file (I checked it when I downloaded it with Firefox).

Why the hell do I only get 5 bytes back and not the 231 I hope (and should recieve, just like Firefox and just like HTTPSniffer tells me)? Or if you got a faster / easier way to download the zip-file trough AutoIt / DLL's etc. tell me please.

Thanks in advance,

Andreas

Edited by Noobster24
Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

Hi,

with this code:

$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open('POST', 'http://www.website.com/d.x')
$oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded')
$oHTTP.Send('ID=N3CRMI8&down_load=Click+here+to+download+the+file')
ConsoleWrite($oHTTP.ResponseText)

I get this response back in the console:

PK

The same result as I got with wininet.dll...

The header that I recieve with above code are correct and the same as with TCP-functions:

Date: Wed, 02 Apr 2008 08:22:58 GMT

Server: Apache/2.0.61 (Unix) PHP/5.2.2

X-Powered-By: PHP/5.2.2

Content-Disposition: filename=filename.zip

Content-Description: filename.zip

Content-Transfer-Encoding: binary

Content-Length: 390

Pragma: no-cache

Expires: 0

Keep-Alive: timeout=15, max=100

Connection: Keep-Alive

Content-Type: application/zip; name=filename.zip

So, that doesn't work for me either :). Got some ideas left?=)
Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

Are you sure you are only getting part of the file? If you are trying to display the contents as text it will probably be cutoff when null characters are encountered. Route the output to FileWrite() after opening with FileOpen() in binary mode.

Link to comment
Share on other sites

$fopen = FileOpen ( @ScriptDir & '\filename.zip', 18 )
$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open('POST', 'http://www.website.com/d.x', 1)
$oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded')
$oHTTP.setTimeouts(5000, 5000, 15000, 15000)
$oHTTP.Send('ID=N3CRMI8&down_load=Click+here+to+download+the+file')
$oHTTP.WaitForResponse
FileWrite ( $fopen, $oHTTP.ResponseText )

If I open the zip with Wordpad / Notepad I still get the first five (5) characters:

PK

I uploaded the zip to the forum so that you can check it for yourself. Edited by Noobster24
Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

Perhaps more information is needed from your original request header in your SetRequestHeader, you only included one line.

That would be unlogic, because I recieve the correct ResponseHeaders from the request...

With this code:

$fopen = FileOpen ( @ScriptDir & '\headers.txt', 2 )
$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open('POST', 'http://www.website.com/d.x', 1)
$oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded')
$oHTTP.setTimeouts(5000, 5000, 15000, 15000)
$oHTTP.Send('ID=N3CRMI8&down_load=Click+here+to+download+the+file')
$oHTTP.WaitForResponse
FileWrite ( $fopen, $oHTTP.GetAllResponseHeaders() )ƒoÝŠ÷ ØŠÞr'¯zØ^±è^i׫²«¨µàÚµäá»MÀ¦½´ÓÍ6ßÝ;ÄÒz»Þ¬
Zr¿ÛNµRx±<sÿçm—>Œ­çAÈñÏÿ¶
‰íz{CŠÊh²+b¢wâ•éÚ™

It gives me a valid filename.zip with contents. As you can see at above code the wininet.dll should work too, because I use the same headers and post data. Maybe you can see what I'm doing wrong with wininet.dll?

Xstandard HTTP Component:

http://www.xstandard.com/en/documentation/xhttp/

I would like to use the wininet.dll because 99,9% of the people have that dll registrerd and installed on their system. If I want to use the XStandard HTTP Component, I have to install + register the dll first. I still don't know what I'm doing wrong when using wininet.dll, I use the same headers, the same postdata, the same PC, etc. :)

Edited by Noobster24
Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

Perhaps more information is needed from your original request header in your SetRequestHeader, you only included one line.

That would be unlogic, because I recieve the correct ResponseHeaders from the request...

With this code:

$fopen = FileOpen ( @ScriptDir & '\headers.txt', 2 )
$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open('POST', 'http://www.website.com/d.x', 1)
$oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded')
$oHTTP.setTimeouts(5000, 5000, 15000, 15000)
$oHTTP.Send('ID=N3CRMI8&down_load=Click+here+to+download+the+file')
$oHTTP.WaitForResponse
FileWrite ( $fopen, $oHTTP.GetAllResponseHeaders() )oÝ÷ ØÞr'¯zØ^±è^i׫²«¨µàÚµäá»MÀ¦½´ÓÍ6ßÝ;ÄÒz»Þ¬
Zr¿ÛNµRx±­çAÈñÏÿ¶
íz{CÊh²+b¢wâéÚ

The filename.zip is a valid archive with contents.

XStandard HTTP Component:

http://www.xstandard.com/en/documentation/xhttp/

I rather like to use the wininet.dll, but that doesn't work for me so far. Maybe anyone can see what I'm overlooking all the time?:)

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
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...