WinHttpRequest (An error occurred in the secure channel support)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
TheDewd
Posts: 1449
Joined: 19 Dec 2013, 11:16
Location: USA

WinHttpRequest (An error occurred in the secure channel support)

19 Oct 2018, 11:31

I'm trying to use WinHttoRequest with POST but I keep receiving the error "An error occurred in the secure channel support".

Any ideas?

Code: Select all

#SingleInstance, Force
#Persistent

Data := "companyName=&address1=1600+Pennsylvania+Ave+NW&address2=&city=DC&state=WA&zip=20500"

WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", "http://tools.usps.com/tools/app/ziplookup/zipByAddress")
WebRequest.SetRequestHeader("Host", "tools.usps.com")
WebRequest.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0")
WebRequest.SetRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01")
WebRequest.SetRequestHeader("Accept-Language", "en-US,en;q=0.5")
WebRequest.SetRequestHeader("Accept-Encoding", "gzip, deflate, br")
WebRequest.SetRequestHeader("Referer", "https://tools.usps.com/zip-code-lookup.htm?byaddress")
WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
WebRequest.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
WebRequest.SetRequestHeader("Content-Length", StrLen(Data))
WebRequest.SetRequestHeader("DNT", "1")
WebRequest.SetRequestHeader("Connection", "keep-alive")
WebRequest.SetRequestHeader("Pragma", "no-cache")
WebRequest.SetRequestHeader("Cache-Control", "no-cache")

StrPut(Data, &Data, "", "UTF-8")

WebRequest.Send(Data)

Result := WebRequest.ResponseText

MsgBox, % Result

Code: Select all

---------------------------
New AutoHotkey Script.ahk
---------------------------
Error:  0x80072F7D - 
Source:		WinHttp.WinHttpRequest
Description:	An error occurred in the secure channel support


HelpFile:		(null)
HelpContext:	0

Specifically: Send

	Line#
	015: WebRequest.SetRequestHeader("X-Requested-With", "XMLHttpRequest")  
	016: WebRequest.SetRequestHeader("Content-Length", StrLen(Data))  
	017: WebRequest.SetRequestHeader("DNT", "1")  
	018: WebRequest.SetRequestHeader("Connection", "keep-alive")  
	019: WebRequest.SetRequestHeader("Pragma", "no-cache")  
	020: WebRequest.SetRequestHeader("Cache-Control", "no-cache")  
	022: StrPut(Data, &Data, "", "UTF-8")  
--->	024: WebRequest.Send(Data)  
	026: Result := WebRequest.ResponseText
	028: MsgBox,Result
	029: Exit
	030: Exit
	030: Exit

Continue running the script?
---------------------------
Yes   No   
---------------------------
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
tmplinshi
Posts: 1600
Joined: 01 Oct 2013, 14:57

Re: WinHttpRequest (An error occurred in the secure channel support)

19 Oct 2018, 16:28

Code: Select all

whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", "https://tools.usps.com/tools/app/ziplookup/zipByAddress")
whr.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
whr.Send("companyName=&address1=1600+Pennsylvania+Ave+NW&address2=&city=DC&state=WA&zip=20500")
MsgBox % whr.ResponseText
User avatar
TheDewd
Posts: 1449
Joined: 19 Dec 2013, 11:16
Location: USA

Re: WinHttpRequest (An error occurred in the secure channel support)

22 Oct 2018, 14:35

I still receive an error. It is probably the security settings for this computer.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 12:16

- You could try this:
oHTTP := ComObjCreate("MSXML2.XMLHTTP.6.0")
- Which is demonstrated here:
Lynda.com workaround - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=61969&p=264597#p264597
- Or try variants of the code by teadrinker in that thread.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1449
Joined: 19 Dec 2013, 11:16
Location: USA

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 12:22

jeeswg wrote:You could try this: oHTTP := ComObjCreate("MSXML2.XMLHTTP.6.0")

Code: Select all

Error:  0x80070005 - Access is denied.
Source:		msxml6.dll
Description:	Access is denied.


HelpFile:		(null)
HelpContext:	0

Specifically: Send

	Line#
	017: WebRequest.SetRequestHeader("X-Requested-With", "XMLHttpRequest")  
	018: WebRequest.SetRequestHeader("Content-Length", StrLen(Data))  
	019: WebRequest.SetRequestHeader("DNT", "1")  
	020: WebRequest.SetRequestHeader("Connection", "keep-alive")  
	021: WebRequest.SetRequestHeader("Pragma", "no-cache")  
	022: WebRequest.SetRequestHeader("Cache-Control", "no-cache")  
	024: StrPut(Data, &Data, "", "UTF-8")  
--->	026: WebRequest.Send(Data)  
	028: Result := WebRequest.ResponseText
	030: MsgBox,Result
	031: Exit
	032: Exit
	032: Exit
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
tank
Posts: 2853
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 14:00

What OS / Browser are you using
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
TheDewd
Posts: 1449
Joined: 19 Dec 2013, 11:16
Location: USA

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 14:16

tank wrote:What OS / Browser are you using
Windows 7 Enterprise Service Pack 1 64-bit

Internet Explorer 11.0.9600.19236
Update Versions: 11.0.105 (KB4480965)
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
tank
Posts: 2853
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 14:42

Sounds like a registry issue but i couldnt point to which key causes it
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 15:20

Some registry keys are mentioned here:
iis - An error occurred in the secure channel support - Classic ASP HTTP Request - Stack Overflow
https://stackoverflow.com/questions/21354992/an-error-occurred-in-the-secure-channel-support-classic-asp-http-request
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1449
Joined: 19 Dec 2013, 11:16
Location: USA

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 16:00

@teadrinker,

Thanks! Unfortunately, I'm using a laptop provided by my workplace, and installing that application requires Administrator privileges that I don't have.

I'm due for a new laptop soon, so hopefully that issue will already be patches on the new machine.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
labrint
Posts: 147
Joined: 14 Jun 2017, 05:06

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 16:13

Is a solution involving code possible? It is not always possible to fix registries of many client pcs.
teadrinker
Posts: 2052
Joined: 29 Mar 2015, 09:41
Contact:

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 16:32

As I understand, the code must be like this:

Code: Select all

RunAsAdmin(true)
RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp, DefaultSecureProtocols, 2560
if A_Is64bitOS
   RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp, DefaultSecureProtocols, 2560

RunAsAdmin(exitIfNotAdmin)  {
   commandLine := DllCall("GetCommandLine", "str")
   isRestarted := !!RegExMatch(commandLine, " /restart(?!\S)")
   
   while !( A_IsAdmin || isRestarted )  {
      try  {
         if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
         else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
      }
      catch
         break 
      ExitApp
   }
   
   if !A_IsAdmin  {
      MsgBox, Failed to run the script as admin!
      if exitIfNotAdmin
         ExitApp
   }
}
Last edited by teadrinker on 21 Feb 2019, 16:37, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinHttpRequest (An error occurred in the secure channel support)

21 Feb 2019, 17:00

- I think the logic would be something like this (if 2 separate writes for 64-bit/32-bit are required):
- Note: I use exactly the same key name both times (I don't use Wow6432Node).

Code: Select all

SetRegView, 64
if A_Is64bitOS
	RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp, DefaultSecureProtocols, 2560
SetRegView, 32
RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp, DefaultSecureProtocols, 2560
- [EDIT:] I think that teadrinker's code would be fine also, assuming that the user hasn't used SetRegView at an earlier point.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
labrint
Posts: 147
Joined: 14 Jun 2017, 05:06

Re: WinHttpRequest (An error occurred in the secure channel support)

26 Feb 2019, 03:01

jeeswg wrote:
21 Feb 2019, 12:16
- You could try this:
oHTTP := ComObjCreate("MSXML2.XMLHTTP.6.0")
- Which is demonstrated here:
Lynda.com workaround - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=61969&p=264597#p264597
- Or try variants of the code by teadrinker in that thread.
This worked for me and all my clients Jeeswg.
User avatar
SKAN
Posts: 853
Joined: 29 Sep 2013, 16:58

WinHttpRequest (An error occurred in the secure channel support) in Win7 x64

15 May 2020, 05:51

I faced this problem today with our forum with WinHttpRequest
Tried to download search results in Win 7 x64
Note: UrlDownload works OK!

1) I installed kb3140245

System re-booted. Download didn't work.

2) Installed MicrosoftEasyFix51044 available in support.microsoft.com

Download didn't work.
I should have atleast logged-off and logged-in :(

3) Changed following keys with hex value of 800 (was A00)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp\DefaultSecureProtocols
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp\DefaultSecureProtocols

I logged-off and logged-in
Download now worked.

I visted support.microsoft.com again and perused.
DefaultSecureProtocols Value Protocol enabled
0x00000008 Enable SSL 2.0 by default
0x00000020 Enable SSL 3.0 by default
0x00000080 Enable TLS 1.0 by default
0x00000200 Enable TLS 1.1 by default
0x00000800 Enable TLS 1.2 by default

For example:
The administrator wants to override the default values for WINHTTP_OPTION_SECURE_PROTOCOLS to specify TLS 1.1 and TLS 1.2.
Take the value for TLS 1.1 (0x00000200) and the value for TLS 1.2 (0x00000800), then add them together in calculator (in programmer mode), and the resulting registry value would be 0x00000A00.
So, I changed the values back to hex value A00
I logged-off and logged-in
Download now works.

I might have to re-install Win 7 in near future, so posting this as a backup.

PS: I don't understand what B grade means: https://www.ssllabs.com/ssltest/analyze.html?d=www.autohotkey.com

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], downstairs, mad3d, WatsonEnterprises, WuffTheCoder and 60 guests