Solved

converting an URL to a stream

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

15 Experts available now in Live!

Get 1:1 Help Now