在 VB6 中使用 MSXML2.ServerXMLHTTP.6.0 的 RPC
我正在与之通信的服务器正在使用 SSL 槽端口 40052 和自签名 CA,在发布之前我已经尝试让它工作大约 2 天,希望有人能提供帮助。
我的问题是当我调用方法 Send
如果没有忽略 ssl 错误,则表示证书颁发机构无效
如果忽略 ssl 错误,则表示服务器返回了无效或无法识别的响应
Dim strXml As String
Dim xmlLength As Integer
strXml = "<?xml version=""1.0""?><methodCall> " & _
"<methodName>somemethod</methodName> " & _
"<params> " & _
"<param><value><string>en</string></value></param>" & _
"<param><value><string>something</string></value></param>" & _
"<param><value><string>00000</string></value></param>" & _
"<param><value><string>000000000000000000000</string></value></param>" & _
"</params>" & _
"</methodCall>"
xmlLength = Len(strXml)
' object to communicate with
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
'since the server i am communicating with is using a self signed certificate authority
' I have to ignore all ssl errors.
xmlHttp.setOption 2, 13056
' I set the friendlyname of my certificate just in case i have tried with and without
xmlHttp.setOption 3, "myrealfriendlynameofcrt"
' I open the connection with the server.
' the server is NOT USING 443 for ssl it's using 50042
xmlHttp.Open "POST", "https://hostname.com:50042", False
' I specify my content type
xmlHttp.SetRequestHeader "Content-Type", "text/xml"
' I specify my content length (I did try with this line and without)
xmlHttp.SetRequestHeader "Content-Length", xmlLength
' I send my request ( MY ERROR OCCURS HERE )
' IF SSL ERRORS NOT IGNORE IT SAYS INVALID CERTIFICATE AUTHORITY
' IF SSL ERRORS IGNORED IT SAYS THE SERVER RETURNED AN INVALID OR UNRECOGNIZED RESPONSE
xmlHttp.send strXml
If xmlHttp.Status >= 400 And xmlHttp.Status <= 599 Then
Debug.Print "Error occured : " & xmlHttp.Status & " - " & xmlHttp.StatusText
Else
Debug.Print xmlHttp.ResponseText
End If
Set xmlHttp = Nothing