/// <exception cref="System.Exception"/> protected internal virtual void _testAuthenticationHttpClient(Authenticator authenticator , bool doPost) { Start(); try { SystemDefaultHttpClient httpClient = GetHttpClient(); DoHttpClientRequest(httpClient, new HttpGet(GetBaseURL())); // Always do a GET before POST to trigger the SPNego negotiation if (doPost) { HttpPost post = new HttpPost(GetBaseURL()); byte[] postBytes = Runtime.GetBytesForString(Post); ByteArrayInputStream bis = new ByteArrayInputStream(postBytes); InputStreamEntity entity = new InputStreamEntity(bis, postBytes.Length); // Important that the entity is not repeatable -- this means if // we have to renegotiate (e.g. b/c the cookie wasn't handled properly) // the test will fail. NUnit.Framework.Assert.IsFalse(entity.IsRepeatable()); post.SetEntity(entity); DoHttpClientRequest(httpClient, post); } } finally { Stop(); } }
private SystemDefaultHttpClient GetHttpClient() { SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient(); httpClient.GetAuthSchemes().Register(AuthPolicy.Spnego, new SPNegoSchemeFactory(true )); Credentials use_jaas_creds = new _Credentials_247(); httpClient.GetCredentialsProvider().SetCredentials(AuthScope.Any, use_jaas_creds); return(httpClient); }