Solved

converting an URL to a stream

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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