将 HttpWebResponse 转换为 HttpResponse
Convert HttpWebResponse to HttpResponse
在 C# 或 VB.Net 中,有一种方法可以将 HttpWebResponse
对象转换为 HttpResponse
,或者直接从 HttpWebRequest
实例中获取 HttpResponse
?
我尝试做的示例(它不起作用):
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url2), HttpWebRequest)
Dim repsonse As HttpResponse = request.GetResponse()
我相信你试图做这样的事情:
var request = WebRequest.Create(collection) as HttpWebRequest;
if (request != null)
using (var stream = request.GetResponse().GetResponseStream())
using (var writer = File.Create(path))
stream.CopyTo(writer);
那会取HttpWebRequest
,然后构建一个Stream
,然后将Stream
复制到一个FileStream
写出内容。你是这个意思吗?
在 C# 或 VB.Net 中,有一种方法可以将 HttpWebResponse
对象转换为 HttpResponse
,或者直接从 HttpWebRequest
实例中获取 HttpResponse
?
我尝试做的示例(它不起作用):
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url2), HttpWebRequest)
Dim repsonse As HttpResponse = request.GetResponse()
我相信你试图做这样的事情:
var request = WebRequest.Create(collection) as HttpWebRequest;
if (request != null)
using (var stream = request.GetResponse().GetResponseStream())
using (var writer = File.Create(path))
stream.CopyTo(writer);
那会取HttpWebRequest
,然后构建一个Stream
,然后将Stream
复制到一个FileStream
写出内容。你是这个意思吗?