WinHTTP.WinHTTPRequest.5.1 在 TLS 1.2 之后不适用于 PayPal 沙箱 [英] WinHTTP.WinHTTPRequest.5.1 does not work with PayPal sandbox after TLS 1.2
问题描述
PayPal 沙箱最近仅限于 TLS 1.2 连接.这使得我们的网站停止使用 PayPal 沙箱,尽管它仍然可以使用生产 PayPal.将来生产的 PayPal 也会有同样的限制.我们使用经典的 ASP 和 Microsoft WinHTTP.WinHTTPRequest.5.1 组件与 PayPal 进行通信.这是下面的代码.objHttp.StatusText 返回错误请求".我们使用的是 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 发送消息;然而,这会导致额外的轻微延迟.
PayPal sandbox just recently restricted to TLS 1.2 connection. This makes our site stop working with PayPal sandbox although it stills work with the production PayPal. In the future the production PayPal will have the same restriction. We're using classic ASP and Microsoft WinHTTP.WinHTTPRequest.5.1 component for communication with PayPal. Here's the code below. objHttp.StatusText returns "Bad Request". We're on Windows Server 2008 R2. I tried to use MSXML2.ServerXMLHTTP.6.0 instead, but it only works on my Windows 8.1 development machine, not on our Windows Server 2008 R2. Although MSXML2.ServerXMLHTTP.6.0 is a superset of WinHTTP.WinHTTPRequest.5.1, but it is less reliable than WinHTTP.WinHTTPRequest.5.1. Our code fails a few times a day using MSXML2.ServerXMLHTTP.6.0 in the past, so I prefer using WinHTTP.WinHTTPRequest.5.1. I'm also not confident in this line of code: objHttp.Option(9) = &H0AA0 . A workaround that we're using is calling the WebAPI for sending message to PayPal; however, this causes an extra minor delay.
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 调用代码:
WebAPI invoke code:
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
推荐答案
我的应用程序是用 ASP 经典编写的,我使用 WinHttp.WinHttpRequest.5.1
代替 MSXML2.ServerXMLHTTP.6.0代码>.发布到贝宝沙箱网址.
My application is written in ASP classic and I use WinHttp.WinHttpRequest.5.1
in place of MSXML2.ServerXMLHTTP.6.0
. to post to paypal sandbox url.
对我有用的是告诉 WinHttp.WinHttpRequest.5.1 对象
使用 TLS 1.2:
What works for me is telling the WinHttp.WinHttpRequest.5.1 objec
to use TLS 1.2:
设置
httpRequest = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
httpRequest.option (9) = 2720
Windows Server 2012 上的所有内容
All that on Windows Server 2012
这篇关于WinHTTP.WinHTTPRequest.5.1 在 TLS 1.2 之后不适用于 PayPal 沙箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!