VB.NET 远程服务器返回错误:(403) Forbidden A FILE DOWNLOAD APP [英] VB.NET The remote server returned an error: (403) Forbidden A FILE DOWNLOAD APP

查看:31
本文介绍了VB.NET 远程服务器返回错误:(403) Forbidden A FILE DOWNLOAD APP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 vb.net 制作文件下载应用程序,但是当我调试应用程序并按下按钮时,我看到了这个错误.我该如何解决这个问题?

I'm trying to make a file download app using vb.net but when i debug the app and press the button i see this error. How can i solve this problem ?

我的代码:

错误:

推荐答案

看起来 thinkbroadband 的服务器不喜欢将该文件提供给它认为是机器人/非真实浏览器的东西.您必须模拟真实的浏览器:

Looks like thinkbroadband's server doesn't like serving that file to things it considers bots/not real browsers. You'll have to mimic a real browser instead:

        Dim x As New WebClient
        x.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36 Edg/83.0.478.45")
        x.DownloadFile("http://download.thinkbroadband.com/10MB.zip", "c:\temp\a.zip")

我怎么知道的?我打开我的浏览器开发者工具 (F12),在浏览器中下载 OK 文件并查看发送了哪些标头以获得 OK 结果,然后将其缩减为仅重要的标头(用户代理)

How did I know this? I opened my browser developer tools (F12), downloaded the file OK in the browser and looked at what headers were sent for an OK result, then pared it down to just the important one (useragent)

这篇关于VB.NET 远程服务器返回错误:(403) Forbidden A FILE DOWNLOAD APP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆