using System; using System.Collections.Generic; //using System.Linq; using System.Net; using System.IO; using System.Text; namespace webrequest_demo.System.Net { public class webrequestExample { public static void Main(String[] args) { try { WebRequest webr = WebRequest.Create(" "http://www.contoso.com/default.html""); webr.Credentials = CredentialCache.DefaultCredentials; WebResponse webresp = webr.GetResponse(); Console.WriteLine(((HttpWebResponse)webresp).StatusDescription); Stream ds = webresp.GetResponseStream(); StreamReader str = new StreamReader(ds); string responseFrommServer = str.ReadToEnd(); str.Close(); webresp.Close(); } catch (WebException wex) { Console.WriteLine(wex.Message); Console.WriteLine(wex.Response); Console.WriteLine(wex.StackTrace); Console.WriteLine(wex.InnerException); } //finally //{ //} Console.ReadLine(); } } }
WebRequest webr = WebRequest.Create(@"http://www.contoso.com/default.html");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)