Jump to content

download file from https (WinHttp.au3)


Kamir
 Share

Recommended Posts


Hi, 
How can I did it? ;)

I download files (XML) from internal website. When I type in webbrowser "https://wso2am.ccc.dd:8877/zzz/firm/1.0/get/TTT/2023-09-18?apikey=zzzzzzzzzzzzzz" then the file appears in the browser.
I can also download this file using cUrl:
curl.exe -k -o tmp\TTT20230918.xml https://wso2am.ccc.dd:8877/zzz/firm/1.0/get/TTT/2023-09-18?apikey=zzzzzzzzzzzzzz

I am trying to download this file using WinHttp, but I don't know how.

I am trying this:

#include "WinHttp.au3"

Local $url = "https://wso2am.ccc.dd/zzz/firm/1.0/get/TTT/2023-09-18"
Local $api = "?apikey=zzzzzzzzzzzzzz"


; Initialize and get session handle
Global $hOpen = _WinHttpOpen()
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, $url, "8243")
If @error Then
    ConsoleWrite("errA: " & @error & @cr)
Else
    ConsoleWrite("hconnect: " & $hConnect & @cr)
EndIf


Local $sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $api)
If @error Then
    ConsoleWrite("errB: " & @error & @cr)
EndIf

$hConnect is OK, but I receive error 02 (could not send request) in _WinHttpSimpleSSLRequest
Why? What am I doing wrong?

Link to comment
Share on other sites

The problem is likely due to a security issue (ie: self signed certificate). You could try adding the following prior to the _WinHttpSimpleSSLRequest --

_WinHttpSetOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS, BitOR($SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, $SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE))

The above was copied from here.

Link to comment
Share on other sites

29 minutes ago, Kamir said:

but now, I've got error 4 (DllCall failed) after _WinHttpSetOption

You didn't post your revised code, so we can only make a guess at the problem. Did you fix up the line I posted to fit with your existing code ($hRequest vs $hOpen)?

What is your OS? Have you verified that _WinHttpCheckPlatform() returns 1?

Link to comment
Share on other sites

Windows 10 64 bit, and 2 yes - I verified that _WinHttpCheckPlatform() returns 1 and of coursce I fix $hRequest to $hOpen. Unfortunately, it is not possible to access this page from outside, so I realize that it is even more difficult to solve the problem. But thank you for your time!

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