Thursday, April 17, 2014
The remote server returned an error 407 Proxy Authentication Required
Code Snippet
- Imports System.Configuration
- Imports System.IO
- Imports System.Net
- Imports System.Text
- Public Class Form1
- Dim InstallerSite As String
- Dim UploadFile As String
- Dim MyProxy As New WebProxy
- Dim ProxyPresent As Boolean
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- InitializeGlobals()
- txtResult.Text = GetFile()
- End Sub
- Private Sub InitializeGlobals()
- InstallerSite = CType(ConfigurationManager.AppSettings("InstallerSite"), String)
- UploadFile = CType(ConfigurationManager.AppSettings("UploadFile"), String)
- ' Case for when a Proxy is present.
- ProxyPresent = CType(ConfigurationManager.AppSettings("ProxyPresent"), Boolean)
- Dim ProxyUrl As String = CType(ConfigurationManager.AppSettings("ProxyUrl"), String)
- Dim ProxyDomain As String = CType(ConfigurationManager.AppSettings("ProxyDomain"), String)
- Dim ProxyUserName As String = CType(ConfigurationManager.AppSettings("ProxyUserName"), String)
- Dim ProxyPassword As String = CType(ConfigurationManager.AppSettings("ProxyPassword"), String)
- Dim credentials As New System.Net.NetworkCredential(ProxyUserName, ProxyPassword, ProxyDomain)
- MyProxy.Address = New Uri(ProxyUrl)
- MyProxy.Credentials = credentials
- End Sub
- Private Function GetFile() As String
- Dim result As String = String.Empty
- Try
- Dim request As HttpWebRequest
- Dim response As HttpWebResponse
- request = WebRequest.Create(InstallerSite & UploadFile)
- If ProxyPresent = True Then
- request.Proxy = MyProxy
- End If
- response = request.GetResponse()
- Dim responseStream As Stream = response.GetResponseStream()
- Dim buffer(10) As Byte
- Dim bytesToRead As Integer = CInt(buffer.Length)
- Dim bytesRead As Integer = 0
- While bytesToRead > 0
- Dim i As Integer = responseStream.Read(buffer, bytesRead, bytesToRead)
- If i = 0 Then
- Exit While
- End If
- bytesRead += i
- bytesToRead -= i
- End While
- result = Encoding.ASCII.GetChars(buffer)
- Catch ex As Exception
- result = ex.Message
- End Try
- Return result
- End Function
- End Class
It turned out they needed to enter the IP address for their proxy domain not just the domain name.
alternative link download
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.