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