简体   繁体   English

如何使用WebClient在C#中下载文件?

[英]how do I download a file in c# using webclient?

I have a java application that downloads a file from a remote server. 我有一个Java应用程序,可从远程服务器下载文件。 I would like to know where the application actually downloads a file. 我想知道应用程序实际在哪里下载文件。 I tried to capture tcp/ip packet and I found out below information. 我试图捕获tcp / ip数据包,但发现以下信息。

protocol: TCP
remote address: xxx.xxx.xxx.xx
local port: xxxx
remote port: xxxxx

I know exact file url now. 我现在知道确切的文件网址。 However, when I try to access the file using web browser I see "internet explorer cannot display the webpage". 但是,当我尝试使用Web浏览器访问文件时,看到“ Internet Explorer无法显示该网页”。

since the application is compiled by java, there must be a way to do it in c#. 由于该应用程序是由Java编译的,因此必须有一种在c#中进行处理的方法。

please advise me.. 请建议我..

Thanks! 谢谢!

Just because the Java application is able to download the file doesn't mean they're doing it via HTTP. 仅仅因为Java应用程序能够下载文件并不意味着他们正在通过HTTP进行下载。 The fact that IE fails to display anything useful suggests it's not HTTP, although that's no guarantee. IE无法显示任何有用的事实表明它不是HTTP,尽管不能保证。

You should look at how the Java application downloads the file, and determine the protocol - that should tell you how to do the same thing from C#. 您应该查看Java应用程序如何下载文件,并确定协议-应该告诉您如何从C#执行相同的操作。

Of course, this is assuming you have the code for the Java application. 当然,这是假设您具有Java应用程序的代码。 If you don't, but you think the authors would be happy for you to download the file with your own code in C#, I suggest you email them to ask them the protocol. 如果您不这样做,但是您认为作者很乐意使用您自己的C#代码下载文件,建议您通过电子邮件向他们询问协议。 If they don't want you accessing the file other than with their application, I'd personally respect their wishes. 如果他们除了您的应用程序之外希望您访问文件,我个人会尊重他们的意愿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM