本文介绍了等效于.NET中的java.net.URLConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否与 java等效.net.URLConnection
类在.NET中.,例如 HttpWebRequest
?还有什么可以用的?
Is there an equivalent of the java.net.URLConnection
classin .NET. , for example the HttpWebRequest
? What else could be used?
推荐答案
可能最接近的是:
WebRequest req = WebRequest.Create(url); // note this is IDisposable so
// should be in a "using" block, or
// otherwise disposed.
因为这将处理多种协议等.但是,如果您的意思是http-我将使用 WebClient
;它比 HttpWebRequest
( WebRequest
实现之一)简单得多.
since this will handle multiple protocols etc. But if you are meaning http - I'd use WebClient
; it is much simpler than HttpWebRequest
(one of the WebRequest
implementations).
如果只想下载一个页面:
If all you want is to download a page:
string s;
using(var client = new WebClient()) {
s = client.DownloadString(url);
}
这篇关于等效于.NET中的java.net.URLConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!