0

我拥有的测试站点显示一个弹出框以输入用户凭据。我可以使用登录到该站点

private CredentialCache GetCredential(LoginData loginData)
{

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    CredentialCache credentialCache = new CredentialCache();
    credentialCache.Add(new System.Uri(loginData.LoginURL), "Basic", new NetworkCredential(loginData.LoginUserName, loginData.LoginPwd));
    return credentialCache;
}

//above code is thanks to another post on SO

public void SiteLogin(LoginData loginData)
{
    CookieContainer cookieContainer = new CookieContainer();
    HttpWebRequest request = WebRequest.Create(loginData.LoginURL) as HttpWebRequest;
    request.CookieContainer = cookieContainer;
    request.Method = WebRequestMethods.Http.Post;
    request.KeepAlive = false;
    request.ContentLength = 0;

    request.Credentials = GetCredential(loginData);
    request.PreAuthenticate = true;



    HttpWebResponse response = request.GetResponse() as HttpWebResponse;

    System.IO.Stream responseStream = response.GetResponseStream();
    System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
    string testString = reader.ReadToEnd(); //see what response is here, only for initial coding

}

我无权访问测试网站,所以我不知道登录弹出窗口的控件名称是什么。

我如何使用 watin 执行类似的步骤?

4

0 回答 0