Solved

converting an URL to a stream

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

Technology Partners: 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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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