2015-04-01 73 views
1

我想发送一个HTTP获取到一个内部网络服务器,这工作正常,除非由于重新路由的原因,用户必须遍历代理才能访问网络服务器,然后我只是得到一个WinInet 12029错误“ERROR_INTERNET_CANNOT_CONNECT尝试连接到服务器失败。”请你能帮我拉现有的Internet选项代理配置?我不想静态定义代理凭证(我也没有尝试过)。Vbscript获取WinINET API的代理配置

我的代码:

Function HTTPGet1 
Dim o, URL, stat 

URL = myURL 
On Error Resume Next 
Set o = CreateObject("Microsoft.XMLHTTP") 
' If Err.Number <> 0 Then 
    'msgbox err.Number & err.Description 
    'msgbox "cake" 
    'Exit Function 
' End if 
o.WinHttpGetIEProxyConfigForCurrentUser 
o.open "GET", URL, False 
o.send 
stat = o.Status 'CInt(o.Status) 
if stat = "200" then 
    msgbox "Account created successfully." 
elseif stat = "" then 
    msgbox "Connection attempt failed due to: " & err.description & "." 
    err.clear 
else 
    msgbox "HTTP error code " & stat & " received." 
end if 
end function 

感谢您的时间!

回答

0

pcap发现服务器正在响应此API无法响应的SSL证书错误。我将它换成了MSXML2.ServerXMLHTTP.6.0,然后能够处理主机名称不匹配。

Function HTTPGet1 
Dim o, address, caseNo, URL, stat 

URL = myURL 
On Error Resume Next 
Set o = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
If Err.Number <> 0 Then 
    msgbox err.Number & err.Description 
    err.clear 
    Exit Function 
End if 
o.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS 
o.open "GET", URL, False 
o.send 
stat = o.Status 

参数“SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS”仅仅是通过API提供的选项之一,这个人是不是最安全的。