本文介绍了无法使用标头中的Windows集成身份验证凭据创建httpwebrequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的C#desktop
程序中使用Windows集成身份验证从HTTP服务器获取一些网页。我不希望用户再次输入用户名,密码或域名。这是我用来尝试测试获取HTTP GET中信息的代码的代码:
//准备请求
HttpWebRequest webrequest =
(HttpWebRequest)WebRequest.Create(" http://test.local/wia" );
webrequest.Method = WebRequestMethods.Http.Get;
webrequest.Accept = " text / plain" ;
webrequest.KeepAlive = false ;
webrequest.AllowAutoRedirect = true ;
webrequest.AllowWriteStreamBuffering = true ;
webrequest.KeepAlive = true ;
webrequest.ContentLength = 0;
webrequest.ProtocolVersion = new 版本(" 1.1" ) ;
CredentialCache cred = new CredentialCache();
cred.Add(" http://test.local.wia" ,8020,"NTLM" ,
CredentialCache.DefaultNetworkCredentials);
webrequest.Credentials = cred;
//显示请求
System.Diagnostics.Debug.WriteLine ("请求信息开始");
System.Diagnostics.Debug.WriteLine(" URI =" +
webrequest.RequestUri) ;
System.Diagnostics.Debug.WriteLine(" Method =" +
webrequest.Method) ;
System.Diagnostics.Debug.WriteLine(" Request Info END" );
System.Diagnostics.Debug.WriteLine(" Request Headers START" );
System.Diagnostics.Debug.WriteLine(webrequest.Headers);
System.Diagnostics.Debug.WriteLine(" Request Headers END" );
解决方案
Hi,
I am trying to use Windows Integrated Authentication in my C# desktop
program to get some web pages from a HTTP server. I don't want the user to
have to type in their username, password or domain again. This is the code I
have been using to try and test getting the credentials into the HTTP GET
message:
// prepare the request HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("http://test.local/wia"); webrequest.Method = WebRequestMethods.Http.Get; webrequest.Accept = "text/plain"; webrequest.KeepAlive = false; webrequest.AllowAutoRedirect = true; webrequest.AllowWriteStreamBuffering = true; webrequest.KeepAlive = true; webrequest.ContentLength = 0; webrequest.ProtocolVersion = new Version("1.1"); CredentialCache cred = new CredentialCache(); cred.Add("http://test.local.wia", 8020, "NTLM", CredentialCache.DefaultNetworkCredentials); webrequest.Credentials = cred; // display the request System.Diagnostics.Debug.WriteLine("Request Info START"); System.Diagnostics.Debug.WriteLine("URI = " + webrequest.RequestUri); System.Diagnostics.Debug.WriteLine("Method = " + webrequest.Method); System.Diagnostics.Debug.WriteLine("Request Info END"); System.Diagnostics.Debug.WriteLine("Request Headers START"); System.Diagnostics.Debug.WriteLine(webrequest.Headers); System.Diagnostics.Debug.WriteLine("Request Headers END");
解决方案
这篇关于无法使用标头中的Windows集成身份验证凭据创建httpwebrequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-13 00:06