我需要訪問SharePoint _api /網絡/列表API。 我有一個FedAuth cookie,我將注入我的HttpWebRequest
。 這是我的代碼的HttpWebRequest的SharePoint API認證FedAuth 401
ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback((object SearchOption, X509Certificate cert, X509Chain chain, SslPolicyErrors sslerror) => true));
var requestUri = this._gedBaseUrl + @"_api/Web/Lists/GetByTitle('Title')/items?$filter=SomeKey eq 'SomeValue'";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);
httpWebRequest.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
httpWebRequest.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
httpWebRequest.Method = WebRequestMethods.Http.Get;
httpWebRequest.AllowAutoRedirect = false;
httpWebRequest.Accept = @"text/html,application/xhtml+xml,*/*";
httpWebRequest.CookieContainer = new CookieContainer();
httpWebRequest.CookieContainer.Add(cookie);
try
{
HttpWebResponse endpointResponse = (HttpWebResponse)httpWebRequest.GetResponse();
}
catch (Exception e)
{
throw e;
}
我有下面的頭錯誤WebException
:
((WebException)e).Response.Headers["X-MSDAVEXT_Error"] "917656; Access denied. Before opening files in this location, you must first browse to the web site and select the option to login automatically."
所以我決定看看我的瀏覽器的Cookie,而且我發送同樣的事情的UserAgent和FedAuth值。
所以我堅持一個HTTP結果401
此代碼工作正常(HTTP結果200),如果我想訪問URL沒有@"_api/Web/Lists/GetByTitle('Title')/items?$filter=SomeKey eq 'SomeValue'";
我也嘗試添加httpWebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
我頭。
如果我深知,這個頭告訴SharePoint服務器使用NTLM身份驗證,這不是我想要的,因爲我的身份驗證方法是基於FedAuth SYSTEME。
我想我失去了一些東西。
我剛纔添加的httpWebRequest.Headers.Add( 「X-FORMS_BASED_AUTH_ACCEPTED」, 「F」);我的要求,我沒有相同的標題答案了,但我仍然有401錯誤:/ – pix