我编写了这个方法来测试凭据,但我不知道为什么当它进入 GetResponse 方法时实际上是运行并运行 web 服务。我只是希望它测试该 Web 服务的凭据是否正确。
private bool TestCredentials(string sURL, ref string sUsername, ref string sPassword)
{
bool retVal = false;
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(sURL), "Full", new NetworkCredential(sUsername, sPassword, "our_domain"));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL);
request.Credentials = myCache;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
retVal = true;
return retVal;