Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 System.Net.WebClient不';你好像没注意到HTTP重定向?_Vb.net_Url_Redirect_Download_Webclient - Fatal编程技术网

Vb.net System.Net.WebClient不';你好像没注意到HTTP重定向?

Vb.net System.Net.WebClient不';你好像没注意到HTTP重定向?,vb.net,url,redirect,download,webclient,Vb.net,Url,Redirect,Download,Webclient,我试图在vb.net中下载一个文件,但从中下载的url会重定向到生成的url 像这样 http://site/yR38aqlDhpV5?token=ykfID 为此: http://site/yR38aqlDhpV5.128.jpg?AWSAccessKeyId=AKIAJBHW5FB4ERKUQUOQ 但是web客户端似乎没有意识到这一点。这有什么办法吗 Dim client As New System.Net.WebClient() client.Download

我试图在vb.net中下载一个文件,但从中下载的url会重定向到生成的url 像这样

http://site/yR38aqlDhpV5?token=ykfID
为此:

http://site/yR38aqlDhpV5.128.jpg?AWSAccessKeyId=AKIAJBHW5FB4ERKUQUOQ
但是web客户端似乎没有意识到这一点。这有什么办法吗

Dim client As New System.Net.WebClient()
            client.DownloadFile(url, sfd.FileName)
            MsgBox("downloaded successfully!")

不幸的是,这不是一个答案,但到底是什么问题?您的代码是否抛出异常,还是根本不下载文件

我很快在C#中编写了完全相同的代码,并尝试从我编写的一个小型Python web服务器下载一个文件(我将其配置为发出一个带有新位置头的301 HTTP响应),该文件下载成功

在WebClient类中,实例化了一个HttpWebRequest对象,该对象处理与HTTP协议的所有交互。它有一个名为“AllowAutoRedirect”的属性,该属性由defaut设置为true;因此,它应该优雅地处理重定向

您可以在reflector或MSDN文档中对此进行验证: