System.Net.WebClient vs. Proxy Authentication 407 error

后端 未结 3 2051
逝去的感伤
逝去的感伤 2021-02-02 18:14

I\'m trying to figure out how to robustly handle proxy authentication errors (HTTP 407 status code) when using the System.Net.WebClient class.

In the field, we see many

3条回答
  •  我在风中等你
    2021-02-02 18:43

    I know this is an old post but I had a similar problem trying to download an XML file using WebClient in an SSIS 2008R2 (SQL Server Integration Services) script task (VB.NET Code) through a Proxy Server to a remote site secured via SSL that also required authentication.

    Took a while to find a solution and this post helped on the proxy side. Below is the script code that worked for me. Might be useful to someone searching for similar.

        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)
    

提交回复
热议问题