Jump to content

WinHTTP


Go to solution Solved by trancexx,

Recommended Posts

  • Solution

kylomas, he means something else.

Spider one, you can do it like this:

#include "WinHttp.au3"

Global Const $sDomain = "https://addons.mozilla.org"
Global $sPage = "firefox/downloads/latest/231203/addon-231203-latest.xpi?src=dp-btn-primary"
Global $sFileName = StringRegExpReplace($sPage, ".*/", "")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$sFileContent = GetTheFileContent($sFileName)

ConsoleWrite($sFileName & @CRLF)
MsgBox(4096, "File Name", $sFileName)

; See what's returned (it's ZIP format so you'll see only first few characters in messagebox)
MsgBox(4096, "Content", $sFileContent)

; The End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Func GetTheFileContent(ByRef $sWEB_FileName)
    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()

    ; Get connection handle
    Local $hConnect = _WinHttpConnect($hOpen, $sDomain)
    ; Register Callback function
    Local Const $hREDIRECT_CALLBACK = DllCallbackRegister(__RedirectFunc, "none", "handle;dword_ptr;dword;ptr;dword")
    ; Set callback
    _WinHttpSetStatusCallback($hConnect, $hREDIRECT_CALLBACK, $WINHTTP_CALLBACK_FLAG_REDIRECT)

    Local $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, Default, $sPage)

    ; Get content disposition
    Local $sDispositionFileName = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_DISPOSITION)

    ; Check if file name is specified inside the header
    If $sDispositionFileName Then $sWEB_FileName = StringReplace(StringRegExpReplace($sDispositionFileName, 'attachment.*=', ""), '"', "")

    ; Read file
    Local $sReturned = _WinHttpSimpleReadData($hRequest)

    ; Close handles
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    ; Free callback
    DllCallbackFree($hREDIRECT_CALLBACK)

    ; All done
    Return $sReturned
EndFunc
; Define callback function
Func __RedirectFunc($hInternet, $iContext, $iInternetStatus, $pStatusInformation, $iStatusInformationLength)
    Local $sStatus = DllStructGetData(DllStructCreate("wchar[" & $iStatusInformationLength & "]", $pStatusInformation), 1)
    Dim $sFileName = StringRegExpReplace($sStatus, ".*/", "")
EndFunc

♡♡♡

.

eMyvnE

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