1

In C# or VB.Net, there is a way to translate an HttpWebResponse object to an HttpResponse, or get directlly an HttpResponse from a HttpWebRequest instance?

Example of what I try to do (it does not work):

Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url2), HttpWebRequest)
Dim repsonse As HttpResponse = request.GetResponse()
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417

1 Answers1

1

I believe your attempting to do something like this:

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);

That will take the HttpWebRequest, then it will build a Stream, and will copy the Stream to a FileStream to write out the contents. Is that what you meant?

Greg
  • 11,302
  • 2
  • 48
  • 79
  • Thanks for answer, but no, sorry, that is not what I mean, but I think I have not clear with my own the concept of what I'm trying to do, just in other question suggested me to use an HttpResponse to try solve a problem, but I can't because I'm using an HttpWebResponse then I thinked to convert the object, please if you can read the comment of @wolfeh in this question it could solve your and my doubt. http://stackoverflow.com/questions/28143651/automate-picture-downloads-from-website-with-authentication – ElektroStudios Jan 28 '15 at 18:00
  • Ironically, the code I posted is used to build a `collection` of data from an API and download all the pages. – Greg Jan 28 '15 at 18:03