大家都在尝试以编程方式登录到网站。我已经在此工作过,但它是一个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