先寫個例子:
// string url = "http://127.0.0.1"
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
request.Timeout = 6000;
HttpWebResponse response = null;
try
{
StreamWriter sw = newStreamWriter(request.GetRequestStream());
...
}
catch(Exception ex)
{
return ex.Message; // 無法連接到遠程服務器
}
然后嘗試在網頁中輸入“http://127.0.0.1”或者"http://localhost/"均被告知無法連接。解決方法是:
本人使用的是win7。打開控制面板 -> 程序 -> 打開或關閉windows功能,如果所示:
稍等片刻,勾選“Internet信息服務”系統會默認勾選上“Web管理工具”和“萬維網服務”后,系統會進行自動更新安裝。成功后,再次輸入“http://127.0.0.1”或“http://localhost/”出現如下效果:
表示OK!