且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我该怎么办摘要式身份验证与HttpWebRequest的?

更新时间:2023-12-01 09:22:34

你说你删除的查询字符串paramters,但你尝试将所有的方式回到刚才主持人? CredentialsCache.Add()我见过的每一个例子似乎只使用主机,和的 CredentialsCache.Add()中URI参数为URI preFIX,这似乎能说明问题。

You said you removed the querystring paramters, but did you try going all the way back to just the host? Every single example of CredentialsCache.Add() I've seen seems to use only the host, and the docs for CredentialsCache.Add() list the Uri parameter as "uriPrefix", which seems telling.

在换句话说,尝试了这一点:

In other words, try this out:

Uri uri = new Uri(url);
WebRequest request = WebRequest.Create(uri);

var credentialCache = new CredentialCache(); 
credentialCache.Add( 
  new Uri(uri.GetLeftPart(UriPartial.Authority)), // request url's host
  "Digest",  // authentication type 
  new NetworkCredential("user", "password") // credentials 
); 

request.Credentials = credentialCache;

如果这个工程,你还必须确保你不添加相同的权威缓存不止一次......到同一主机的所有请求应该能够使用相同的凭证缓存项。

If this works, you will also have to make sure that you don't add the same "authority" to the cache more than once... all requests to the same host should be able to make use of the same credential cache entry.