Web Service 使用時出現 HTTP Status 401: Unauthorized




在調用 Web Service 時,實際遇到的情況:

1, 如果當前用戶有權限,且IIS 中設定禁止匿名訪問,則需要在代碼中增加以下代碼:

webService.UseDefaultCredentials = true

2,如果當前用戶沒有權限,但IIS 中設定禁止匿名訪問,就會出現此401 錯誤,可開啓匿名訪問解決:

enable anonymous authentication

3,如果當前用戶沒有權限,但IIS 中設定禁止匿名訪問,會出現401 錯誤,在不開啓匿名訪問的前提下,需要在代碼中加入對應的認證代碼解決:

ws.Credentials = new System.Net.NetworkCredential(_userID, _password);




參看以下文章:

Http 401錯誤重現實驗及解決辦法

http://blog.csdn.net/directionofear/article/details/8042755



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章