English 中文(简体)
WebClient下载文档有误: 不针对物体的事例提出反对
原标题:WebClient Download file got error: Object reference not set to an instance of an object
WebClient ws = new WebClient();
ws.Credentials = new System.Net.NetworkCredential(username, password, domain);
 ws.DownloadFile("https://xxxx.xxxx.com/xxxx.xml", @"C:WindowsTEMPDownloaded.xml");

I got error Object reference not set to an instance of an object . Anyone know why?

如果我把“https://xx.xx.com/xxxx.xml”复制到浏览器上,可以下载并节省到“C:WindowsTEMPDownloaded.xml”,但我的节目不能只留下错误。

此前,我使用同一代码成功地下载了档案,但这是另一个网站,有http://www.un.org。 无法确定这一问题的原因。

问题回答

我在使用网上课时也存在同样的问题。 我确实是在建立国际投资协会,而不是像现在这样铺设道路(我在此没有这样做,但你还可以给UriBuilder增加用户名和密码):

var uriBuild = new UriBuilder { Host host, Path = downloadPath };
client.DownloadFileAsync(uriBuild.Uri, localPath);

东道和下载的道路是连续的,例如:

string host = "ftp.sunet.se"
string downloadPath = "/pub/unix/databases/relational/mysql/Downloads/MySQL-5.5/mysql-5.5.22-win32.msi"

Let me know if this also works for you! Cheers :)

1. 使用尿素而不是使用原始尿素

Uri URL = urlAddress.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("https://" + urlAddress);
await myWebClient.DownloadFileTaskAsync(URL, location);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签