Given the URL in the line:
http:
What is the easiest / shortest way to load the contents of a file from a server (with a URL) into a string in C #?
The way I'm doing it now is:
WebRequest request = WebRequest.Create("http://www.example.com/test.xml"); WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd();
This is a lot of code, which can essentially be a single line:
string responseFromServer = ????.GetStringFromUrl("http://www.example.com/test.xml");
Note. Asynchronous calls don't bother me - this is not production code.
rein Jun 26 '09 at 9:26 a.m. 2009-06-26 09:26
source share