大家都在嘗試以編程方式登錄到網站。我已經在此工作過,但它是一個php頁面,我使用下面的代碼(在Stack Overflow中找到了一些地方)登錄到它,它工作得很好。以編程方式登錄到使用IIS身份驗證的網站
private static string GetDataFromPHP(string formUrl, string getUrl, string username, string password, out bool status)
{
try
{
string formParams = string.Format("access_login={0}&access_password={1}", username, password);
string cookieHeader;
WebRequest req = WebRequest.Create(formUrl);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(formParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
WebResponse resp = req.GetResponse();
cookieHeader = resp.Headers["Set-cookie"];
string pageSource;
WebRequest getRequest = WebRequest.Create(getUrl);
getRequest.Headers.Add("Cookie", cookieHeader);
WebResponse getResponse = getRequest.GetResponse();
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
pageSource = sr.ReadToEnd();
}
status = true;
return pageSource;
}
catch (System.Exception ex)
{
status = false;
return string.Empty;
}
}
凡access_login & access_password是接受credentials.I不知道如何實現它的IIS登錄提示如圖所示。請到幫助輸入框的名稱
感謝讓我試試 – Karthik 2013-05-13 06:05:34