Solved

converting an URL to a stream

Posted on 2004-04-07
4
543 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now