J'ai besoin d'accéder à l'API Sharepoint _api/Web/Lists. J'ai un cookie FedAuth que je vais injecter dans mon HttpWebRequest
. Ceci est mon codeHttpWebRequest Sharepoint API Authentification 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;
}
J'ai un WebException
avec l'erreur d'en-tête suivant:
((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."
ai donc décidé de regarder les cookies de mon navigateur, et je vous envoie les mêmes choses UserAgent et FedAuth valeur.
Je suis coincé avec un résultat http 401.
Ce code fonctionne très bien (http résultat 200) si je veux accéder à l'URL sans @"_api/Web/Lists/GetByTitle('Title')/items?$filter=SomeKey eq 'SomeValue'";
J'essaie aussi d'ajouter httpWebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
à mon en-têtes. Si j'ai bien compris, cet en-tête dit au serveur Sharepoint d'utiliser l'authentification NTLM, ce n'est pas ce que je veux, car ma méthode d'authentification est basée sur FedAuth systeme.
Je pense qu'il me manque quelque chose.
Je viens d'ajouter le httpWebRequest.Headers.Add ("X-FORMS_BASED_AUTH_ACCEPTED", "f"); à ma demande, je n'ai plus les mêmes en-têtes de réponse, mais j'ai toujours l'erreur 401: / – pix