开发者

Equivalent of java.net.URLConnection in .NET

开发者 https://www.devze.com 2023-01-28 21:34 出处:网络
Is there an equivalent of the java.net.URLConnection class in .NET. , for example the HttpWebRequest? What开发者_运维百科 else could be used?Probably the closest is:

Is there an equivalent of the java.net.URLConnection class in .NET. , for example the HttpWebRequest? What开发者_运维百科 else could be used?


Probably the closest is:

WebRequest req = WebRequest.Create(url); // note this is IDisposable so
                                         // should be in a "using" block, or
                                         // otherwise disposed.

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);
}


HttpWebRequest and WebClient are as close as I can see.

Is there a specific feature or set of features that you require?

0

精彩评论

暂无评论...
验证码 换一张
取 消