将 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写出内容。你是这个意思吗?