public void sovGodt() throws ClientProtocolException, IOException, AuthenticationException {
Log.d(TAG, "sovGodt...");
// Instantiate the custom HttpClient
HttpGet get = new HttpGet(UURRL);
get.setHeader("Content-type", "application/json");
get.setHeader("Accept", "application/json");
get.setHeader("X-Requested-With", "json");
// String source = "Erna:Erna";
// String ret = "Basic " + Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP);
// get.setHeader("Authorization", ret);
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("Erna", "Erna");
// get.setHeader(new BasicScheme().authenticate(creds, get));
get.setHeader(BasicScheme.authenticate(creds, "UTF-8", false));
// String x = "Erna:Erna";
// String encoding = Base64.encode(x.getBytes(), Base64.DEFAULT).toString();
// get.setHeader("Authorization", "Basic " + encoding);
// CredentialsProvider credProvider = new BasicCredentialsProvider();
// credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
// new UsernamePasswordCredentials("Erna", "Erna"));
// client.setCredentialsProvider(credProvider);
// client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
// new UsernamePasswordCredentials("Erna", "Erna"));
// Execute the GET call and obtain the response
Long s1 = System.currentTimeMillis();
HttpResponse getResponse = client.execute(get);
Log.d(TAG, "Time..:" + (System.currentTimeMillis() - s1) + " ms");
HttpEntity entity = getResponse.getEntity();
InputStream is = entity.getContent();
Log.d(TAG, "response...:" + convertStreamToString(is));
}
0 Responses to "Basic Http Authentication":
Post a Comment