HTTP状态401请求失败:未经授权。为什么?在C#中开发的.net webservices中出现'未授权'错误。
TravelCodesTranslator ws = GetEncodeDecodeWS();
// Create and set up the credentials for XmlSelectWebService
string UserName = "username";
string Password = "pwd";
// Xml Select uses Basic Authentication
NetworkCredential credentials = new NetworkCredential(UserName, Password);
CredentialCache cc = new CredentialCache();
ws.PreAuthenticate = true;
ws.Credentials = credentials;
XmlElement response;
if (_requestType == "Encode")
{
response = ws.Encode(request.DocumentElement); // got error of
// "The request failed
// with HTTP status 401:
// Unauthorized."
}
else
{
response = ws.Decode(request.DocumentElement);
}
再次编辑您的问题以删除用户名和密码。请不要在公共场所张贴敏感数据。 – Shoban