Solved

converting an URL to a stream

Posted on 2004-04-07
4
547 Views
Last Modified: 2011-09-20
Hi,
here is my code. i am trying to open up a website & convert it to stream.

WebRequest request = WebRequest.Create("http://www.microsoft.com");
string Response = loResponseStream.ReadToEnd();
WebResponse response = request.GetResponse();
StreamReader  reader = new StreamReader(response.GetResponseStream());
string str  = reader.ReadBlock();
Response.Write(str);

when i do this , the text part gets written. i want to write the images too.
pls help asap.
0
Comment
Question by:chandua
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10777290
what do you mean that you aso want to get the images ? In order to capture the actual images you would have to capture them seperately i.e. parse the html download the images and replace the text  in the return document ...

if you are simply trying to show someone a page from elsewhere then you should look at how relative URLs are processed and how they can be overriden in a document i.e. you can tell the document to use microsoft.com as the base url for relative urls ... this can be seen in RFC1808 http://www.w3.org/TR/WD-html40-970708/references.html#ref-RFC1808 ...

one way is to use the <base /> element to change this for a document.

ex: <base href="http://microsoft.com/" />

more help http://webdesign.about.com/library/tags/bltags-base.htm

Greg
0
 

Author Comment

by:chandua
ID: 10777344
i am not trying to show a page elsewhere.

need to capture images too.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10777875
You are writing the response out as your response
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 100 total points
ID: 10777941
doh ...
You are writing the response out as your response.

Since you are wiritng it frm a different base URL the relative urls will be broken in that page unless you set the baseurl specifically or that page already does it. Otherwise all of the relative links will be broken. If it is set then the images will show up. An example of this could be seen by trying your code on a simple web page where you use all absolute references ... If you actually need to download the images to your server you can do this by parsing the html for <img> elements, grab the url and create another request asking for the image ...

You can do something like ... WebRequest request = WebRequest.Create("http://www.microsoft.com/fubar.gif");


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question