HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://YOUR_URL/"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); string result = sr.ReadToEnd();
但如果我們因為參數或網址錯誤,導致網站回應錯誤,就會取得如 400 Bad Request、404 Not Found...等等的這種http status,在瀏覽器上就會看到像這樣的畫面: