将HttpWebResponse转换为HttpResponse

时间:2015-01-28 17:44:09

标签: c# .net vb.net http httpresponse

C# VB.Net 中,有一种方法可以将HttpWebResponse对象翻译为HttpResponse,或者直接获得HttpResponse来自HttpWebRequest实例的{1}}

我尝试做的例子(它不起作用):

Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url2), HttpWebRequest)
Dim repsonse As HttpResponse = request.GetResponse()

1 个答案:

答案 0 :(得分:1)

我相信你试图做这样的事情:

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以写出内容。那是你的意思吗?