等效于.NET中的java.net.URLConnection

编程入门 行业动态 更新时间:2024-10-24 20:23:58
本文介绍了等效于.NET中的java.URLConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否与 java等效.URLConnection 类在.NET中.,例如 HttpWebRequest ?还有什么可以用的?

Is there an equivalent of the java.URLConnection class in .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

本文发布于:2023-11-17 04:36:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java   NET   URLConnection   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!