[英]Web Service 401: Unauthorized Error
I am running a web service locally that connects to an outside server that i do not have access to. 我在本地运行一个Web服务,连接到我无法访问的外部服务器。
I keep receiving the "401: Unauthorized" error even though the test credentials are confirmed exactly correct by the admins of this web service. 即使此Web服务的管理员确认测试凭据完全正确,我仍然收到“401:Unauthorized”错误。
Do i need to adjust any IIS settings? 我需要调整任何IIS设置吗?
Here is a screenshot of the error. 这是错误的屏幕截图。
// Webservice
IdentityService ws = new IdentityService();
// Test Static Credentials
string username = "twfnf";
string password = "testme99";
string domain = "testapps1";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(ws.Url), "Basic", credentials);
ws.Credentials = credCache;
ws.PreAuthenticate = true;
ws.AuthenticateUser();
Removing the following code with Basic Authentication, fixed the issue. 使用基本身份验证删除以下代码,修复了该问题。
CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(ws.Url), "Basic", credentials);
Final Code Working: 最终守则工作:
// Webservice
IdentityService ws = new IdentityService();
// Test Static Credentials
string username = "twfnf";
string password = "testme99";
string domain = "testapps1";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
ws.Credentials = credentials;
ws.PreAuthenticate = true;
ws.AuthenticateUser();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.