Home > Net >  C # httpwebrequest login website integrated Windows authentication, user id and password
C # httpwebrequest login website integrated Windows authentication, user id and password

Time:11-25

This is fiddler access to the response of the

HTTP/1.1 401 Unauthorized
Cache-control: private
The content-type: text/HTML
Server: Microsoft IIS/8.5
X - AspNet - Version: 4.0.30319
The Set - cookies:. ASPXAUTH=; Expires=Mon, 11 - Oct - 1999 16:00:00 GMT; Path=/; HttpOnly
X - Frame - Options: SAMEORIGIN
The Content ws-security - Policy: frame - ancestors' self '
X - the content-type - Options: nosniff
WWW - Authenticate: Negotiate
WWW - Authenticate: NTLM
X - Powered By: ASP.NET
P3P: CP="NON"
X - XSS - Protection: 0
The Content - Length: 1181
The Proxy - Support: the Session -- -based Authentication
Here is my code
 

ServicePointManager. ServerCertificateValidationCallback=new System.Net.Security.RemoteCertificateValidationCallback (CheckValidationResult);//verify the server certificate automatic validation callback
HttpWebRequest the req=(HttpWebRequest) HttpWebRequest. Create (" url ");

The req. PreAuthenticate=true;
The req. UseDefaultCredentials=false;
Var c=new NetworkCredential (" user ", "password");
CredentialCache CredentialCache=new CredentialCache ();
CredentialCache. Add (new Uri (" url "), "Negotiate", c);

The req. KeepAlive=true;

The req. Credentials=credentialCache;

The req. Method="GET";
The req. Host="";
//the req. ContentType="application/x - WWW - form - urlencoded";
The req. Accept="text/HTML, application/XHTML + XML, application/XML. Q=0.9, image/webp, */*; Q=0.8 ";
The req. Headers. The Add (" Upgrade - the Insecure - Requests ", "1");
The req. UserAgent="Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36".
The req. Headers. The Add (" cache-control ", "Max - age=0");
The req. Headers. The Add (" Accept - the Encoding ", "gzip, deflate, SDCH");
The req. Headers. Add (" Accept - Language, "" useful - CN, useful; Q=0.8 ");

HttpWebResponse res=null;


Try
{
Res=(HttpWebResponse) the req. The method GetResponse ();
}
The catch (WebException er)
{
Res=(HttpWebResponse) er. The Response;
}


Return the result has been a 401, why? Browser enter account and password can log in and is HTTPS web site

CodePudding user response:

Need the password encryption
  • Related