這是fiddler獲取到的response
HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
Set-Cookie: .ASPXAUTH=; expires=Mon, 11-Oct-1999 16:00:00 GMT; path=/; HttpOnly
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-Content-Type-Options: nosniff
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
P3P: CP="NON"
X-XSS-Protection: 0
Content-Length: 1181
Proxy-Support: Session-Based-Authentication
下面是我的代碼
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//驗證服務器證書回呼自動驗證
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("url");
req.PreAuthenticate = true;
req.UseDefaultCredentials = false;
var c = new NetworkCredential("user", "password");
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new Uri("url"), "Negotiate", c);
req.KeepAlive = true;
req.Credentials = credentialCache;
req.Method = "GET";
req.Host = "";
//req.ContentType = "application/x-www-form-urlencoded";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
req.Headers.Add("Upgrade-Insecure-Requests", "1");
req.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36";
req.Headers.Add("Cache-Control", "max-age=0");
req.Headers.Add("Accept-Encoding", "gzip, deflate, sdch");
req.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
HttpWebResponse res = null;
try
{
res = (HttpWebResponse)req.GetResponse();
}
catch (WebException er)
{
res = (HttpWebResponse)er.Response;
}
回傳結果一直是401,為什么?瀏覽器輸入賬號和密碼就能登錄進去了,網站是https的
uj5u.com熱心網友回復:
需要把密碼加密嗎轉載請註明出處,本文鏈接:https://www.uj5u.com/net/41631.html
標籤:ASP.NET
上一篇:討論下,行程間通信的問題
下一篇:C# 呼叫RsiOPCAuto.DLL 連接OPC服務器,報錯:沒有注冊介面(例外 hresult:0x80040155)
