Grundlegende Authentifizierung mit HTTP Commons Client
Ich schaue auf diesen Link und versuche, Anfragen an den Server zu senden
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html
public class Test {
public static void main(String[] args) throws ClientProtocolException, IOException {
DefaultHttpClient httpClient;
URL url = new URL("https://9.5.127.34:443");
httpClient = getSSLHttpClient(url);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("https://9.5.127.34", AuthScope.ANY_PORT),
new UsernamePasswordCredentials("root", "passw0rd"));
httpClient.setCredentialsProvider(credsProvider);
HttpGet httpget = new HttpGet("https://9.5.127.34/powervc/openstack/volume/v1/115e4ad38aef463e8f99991baad1f809//volumes/3627400b-cd98-46c7-a7e2-ebce587a0b05/restricted_metadata");
HttpResponse response = httpClient.execute(httpget);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
Aber es gibt mir als Fehler
Authentication required
Bitte sag mir, was ich falsch mache. Vielen Dank im Voraus