我知道这是一篇旧文章,但我在尝试通过代理服务器在 SSIS 2008R2(SQL Server 集成服务)脚本任务(VB.NET 代码)中使用 WebClient 将 XML 文件下载到通过 SSL 保护的远程站点时遇到了类似的问题这也需要身份验证。
花了一段时间才找到解决方案,这篇文章在代理方面有所帮助。下面是对我有用的脚本代码。可能对搜索类似内容的人有用。
Dim objWebClient As WebClient = New WebClient()
Dim objCache As New CredentialCache()
'https://www.company.net/xxxx/resources/flt
Dim strDownloadURL As String = Dts.Variables("FileURL").Value.ToString
'apiaccount@company.net
Dim strLogin As String = Dts.Variables("FileLogin").Value.ToString
'sitepassword
Dim strPass As String = Dts.Variables("FilePass").Value.ToString
'itwsproxy.mycompany.com
Dim strProxyURL As String = Dts.Variables("WebProxyURL").Value.ToString
'8080
Dim intProxyPort As Integer = Dts.Variables("WebProxyPort").Value
'Set Proxy & Credentials as a Network Domain User acc to get through the Proxy
Dim wp As WebProxy = New WebProxy(strProxyURL, intProxyPort)
wp.Credentials = New NetworkCredential("userlogin", "password", "domain")
objWebClient.Proxy = wp
'Set the Credentials for the Remote Server not the Network Proxy
objCache.Add(New Uri(strDownloadURL), "Basic", New NetworkCredential(strLogin, strPass))
objWebClient.Credentials = objCache
'Download file, use Flat File Connectionstring to save the file
objWebClient.DownloadFile(strDownloadURL, Dts.Connections("XMLFile").ConnectionString)