Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net &引用;远程服务器返回错误(502)坏网关;从url下载图像文件时_Vb.net - Fatal编程技术网

Vb.net &引用;远程服务器返回错误(502)坏网关;从url下载图像文件时

Vb.net &引用;远程服务器返回错误(502)坏网关;从url下载图像文件时,vb.net,Vb.net,我试图从网站下载图像,但它给了我错误,即(远程服务器返回错误:(502)坏网关)。我在网上搜索了很多,但没有找到确切的答案。此代码在某些网站上运行,但在少数网站上显示上述错误。 请检查我下面的代码 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim filename As String = Application.Startup

我试图从网站下载图像,但它给了我错误,即(远程服务器返回错误:(502)坏网关)。我在网上搜索了很多,但没有找到确切的答案。此代码在某些网站上运行,但在少数网站上显示上述错误。 请检查我下面的代码

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 &= "\"
    txtLocalFile.Text = "D:\a.jpg" 'filename & " "
    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

你能告诉我代码的哪一部分丢失了或者我必须更改吗?

我做了一些RND,最后我的代码开始工作了

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 &= "\"
    txtLocalFile.Text = "" 'filename & " "
    txtRemoteFile.Text = ""
End Sub

Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
    Application.DoEvents()
    Dim web_client As WebClient = New WebClient
    Try
        web_client.UseDefaultCredentials = True
        web_client.DownloadFile(txtRemoteFile.Text, txtLocalFile.Text)
        MessageBox.Show("Done")

    Catch ex As Exception
        Dim wp = New WebProxy("Proxy IP", Proxy_port)
        wp.Credentials = New NetworkCredential("MachineUsername", "Machine Password", "Domain Name")
        web_client.Proxy = wp
        web_client.DownloadFile(txtRemoteFile.Text, txtLocalFile.Text)
        MessageBox.Show("Done")
    End Try

End Sub

这是服务器上的一个错误。如果您拥有服务器上的代码,请查看那里。如果您没有,请联系支持团队并寻求他们的帮助。@tim。。你认为服务器上的代码有什么问题……我不知道,但服务器出了问题。这就是为什么我建议您查看服务器上的代码(和日志)(如果您拥有),或者联系相关人员。@tim。。好啊感谢您的回复…请尝试设置UserAgent。例如
web_client.UserAgent=“Mozilla/4.0(兼容;MSIE 7.0;Windows NT 5.1)”。有些网站出于安全原因需要这样做。