是否有与 java.net.URLConnection
等效的内容类(class)
在.NET中。 ,例如 HttpWebRequest
?还能用什么?
最佳答案
可能最接近的是:
WebRequest req = WebRequest.Create(url); // note this is IDisposable so
// should be in a "using" block, or
// otherwise disposed.
因为这将处理多个协议(protocol)等。但如果你指的是http - 我会使用WebClient
;它比 HttpWebRequest
(WebRequest
实现之一)简单得多。
如果您只想下载页面:
string s;
using(var client = new WebClient()) {
s = client.DownloadString(url);
}
关于java - .NET 中 java.net.URLConnection 的等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345340/