c# - 将 HttpWebResponse 转换为 HttpResponse

标签 c# .net vb.net http 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# - 将 HttpWebResponse 转换为 HttpResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28198904/

相关文章:

c# - 在 Windows 8/RT 应用程序中处理位图

c# - 自定义类型相关的模板加载器

c# - SQL Select 数据变化时

c# - Application_Start 是否在 Web.config 文件转换之前执行?

vb.net - 如何使用 VB.NET 将 XLS 中的单个工作表转换为 PDF

c# - FakeItEasy 返回调用该方法的对象

.net - 如何赋予程序比启动它的用户更多的权限

c# - 为什么我不能将 Foo<Bar> 转换为 IFoo<IBar>

从创建它的线程以外的线程访问 vb.net

mysql - vb net SQl查询问题