title: "The remote server returned an error (502) Bad Gateway" while downloading image file from url
body: <p>I am trying to download image from website, but it gives me error i.e. (The remote server returned an error: (502) Bad Gateway). I search a lot on internet but didn't get exact solution. This code is working on some website but on few website it is showing above error.
  Please check my below code...</p>
  
  <pre><code>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim filename As String = Application.StartupPath
      If Not filename.EndsWith("\") Then filename &amp;= "\"
      txtLocalFile.Text = "D:\a.jpg" 'filename &amp; " "
      txtRemoteFile.Text = "http://bseworld.bseindia.com/eventgallery/cricket2015/19Feb2015/2.jpg"
  End Sub
  
  
  Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
      Application.DoEvents()
      Try
          Dim web_client As WebClient = New WebClient
  
          Dim wp = New WebProxy("proxy ip", proxy_port)
          wp.Credentials = New NetworkCredential("uname", "password", "domainname")
          web_client.Proxy = wp
          web_client.DownloadFile(txtRemoteFile.Text, txtLocalFile.Text)
  
          MessageBox.Show("Done")
      Catch ex As Exception
  
      End Try
  
      End Sub
  </code></pre>
  
  <p>Can you please tell me which part of code is missing or i have to change..</p>