Code example for AuthScope

0
		int port = hostUri.getPort() == -1 ? 80 : hostUri.getPort(); 
		 
		if(useAuth) 
		{ 
			String hostname = hostUri.getHost();
			((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
                new AuthScope(hostname, port), 
                new UsernamePasswordCredentials(username, password));
		} 
	} 
 
	protected Uri getHostUri(String path) throws Exception {
		String host = preferences.getString("hostname_preference", null);
		 
		if(host == null) 
		{ 
			throw new Exception("No host is configured.");
		} 
		 
		if(host.toLowerCase().startsWith("http://") == false) { 
Connect your IDE to all the code out there  Get Codota for Java