public BeamHttpClient(BeamAPI beam, String httpUsername, String httpPassword, String oauthToken) { this.beam = beam; this.cookieStore = new BasicCookieStore(); if (httpUsername != null && httpPassword != null) { this.context = HttpClientContext.create(); AuthCache ac = new BasicAuthCache(); ac.put(new HttpHost(this.beam.basePath.getHost()), new BasicScheme()); this.context.setAuthCache(ac); CredentialsProvider cp = new BasicCredentialsProvider(); cp.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(httpUsername, httpPassword) ); this.context.setCredentialsProvider(cp); } else { this.context = null; } this.http = this.buildHttpClient(); if (oauthToken != null) { this.oauthToken = oauthToken; } }
protected HttpClient GetClient() { NetworkCredential cred = new NetworkCredential(UserName, Password); HttpClient cli = new HttpClient(MsgHandler()); HttpHost targetHost = new HttpHost("localhost", 8080, "http"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS)); AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); // Add AuthCache to the execution context final HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); //WebRequest req = WebRequest.Create("http://" + Address.ToString() + "/en/" + f); //req.Credentials = new NetworkCredential(UserName, Password); }