WinHTTP.WinHTTPRequest.5.1在TLS 1.2之后无法与PayPal沙盒一起使用

4

PayPal沙盒最近仅限于TLS 1.2连接。这使得我们的网站无法与PayPal沙盒进行通信,尽管它仍然能够与生产PayPal进行通信。未来,生产PayPal也将有同样的限制。我们正在使用经典ASP和Microsoft WinHTTP.WinHTTPRequest.5.1组件与PayPal进行通信。以下是代码,objHttp.StatusText返回“Bad Request”。我们使用的是Windows Server 2008 R2。我试图使用MSXML2.ServerXMLHTTP.6.0替代,但它只在我的Windows 8.1开发机器上工作,而不在我们的Windows Server 2008 R2上工作。虽然MSXML2.ServerXMLHTTP.6.0是WinHTTP.WinHTTPRequest.5.1的超集,但它比WinHTTP.WinHTTPRequest.5.1不可靠。我们的代码每天使用MSXML2.ServerXMLHTTP.6.0失败几次,因此我更喜欢使用WinHTTP.WinHTTPRequest.5.1。我对这行代码也不太自信:objHttp.Option(9) = &H0AA0。我们正在使用的解决方法是调用WebAPI向PayPal发送消息;但是,这会导致额外的轻微延迟。

dim objHttp
Set objHttp = Server.CreateObject("WinHTTP.WinHTTPRequest.5.1")
dim WinHttpRequestOption_EnableHttp1_1 : WinHttpRequestOption_EnableHttp1_1 = 17
objHttp.Option(WinHttpRequestOption_EnableHttp1_1) = False

dim WinHttpRequestOption_SslErrorIgnoreFlags : WinHttpRequestOption_SslErrorIgnoreFlags=4
objHttp.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300
objHttp.setTimeouts 0, 120000, 120000, 120000 
objHttp.Option(9) = &H0AA0 '2720
objHttp.open "post", "" & "https://api-3t.sandbox.paypal.com/2.0/" & "", False
strRequest = SetExpressCheckoutSOAP(returnURL, cancelURL)
objHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objHttp.setRequestHeader "Content-Length", Len(strRequest)

objHttp.setRequestHeader "Host", "api-3t.sandbox.paypal.com"
Call objHttp.send(strRequest)
if objHttp.Status = 200 then
   resp = objHttp.responseText
else
   response.write objHttp.StatusText
end if

WebAPI调用代码:

dim webapiresp, webapidata
webapidata = "{""url"":""" & gv_APIEndpoint & """, ""message"":""" & nvpStrComplete & """,""soap"":0}"
webapiresp=InvokeWebAPI(strApiDomain, "POST", "comm/send", "", webapidata)
        set reply=JSON.parse(webapiresp)
        resp = reply.xml

Function InvokeWebAPI(strApiDomain, method, funcname, param, data)
dim HttpReq, apiURI, resp

set HttpReq=Server.CreateObject("MSXML2.ServerXMLHTTP")
'apiURI=strApiDomain & funcname & param
apiURI=strApiDomain & "api/" & funcname & param


HttpReq.open method, apiURI, false

HttpReq.setRequestHeader "Content-Type", "application/json; charset=UTF-8"
HttpReq.setRequestHeader "SOAPAction", apiURI
HttpReq.setRequestHeader "Authorization", "Basic " & Base64Encode("xxx:xxx")

if data <> "" then
    HttpReq.send data
else
    HttpReq.send 
end if

resp = HttpReq.responseText

set HttpReq=Nothing

InvokeWebAPI = resp
End Function
4个回答

2

这个选项:

httpRequest.option (9) = 2720

仅适用于Windows 2012及以上版本

Windows 2008 R2的系统库"winhttp.dll"只有TLS 1.0的记录,相当于:

httpRequest.option (9) = 128

其他的数值会抛出异常。但我找到了一个解决方案,只需要在注册表中进行更改,而不需要对代码进行任何其他更改。 详见此处: Classic ASP Outbound TLS 1.2

2

我的应用程序是用ASP经典编写的,我使用WinHttp.WinHttpRequest.5.1来代替MSXML2.ServerXMLHTTP.6.0。以将数据发布到PayPal沙盒网址。

对我有效的方法是告诉WinHttp.WinHttpRequest.5.1对象使用TLS 1.2:

设置

httpRequest = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
httpRequest.option (9) = 2720

所有这些都是关于Windows Server 2012的。


1

0
首先,您需要在服务器上启用对TLS 1.2的支持(我更喜欢使用免费的IISCrypto工具来自Nartac Software)。
然后,您可以通过设置以下注册表键来更改默认行为:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]
"DefaultSecureProtocols"=dword:00000800

如果您正在使用32位应用程序,则还需要此密钥:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]
"DefaultSecureProtocols"=dword:00000800

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接