cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error sending Java request to cloud-cap-samples-java

Abdurahman
Associate
Associate
0 Likes
151

I'm trying to send a request using Java to the application e.g http://localhost:8080/api/admin/Addresses but I keep getting 401 unauthorized even though I'm sending the request with the required credentials. I'm using the admin user for this request so username is admin and password is also admin.

This is the Java code I'm trying to use to accomplish this: 

 

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.GET()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("Authorization", "Basic YWRtaW46YWRtaW4=")
.build();

It works when I'm sending it with Postman, Curl, I even tried to use Node.js and there were no issues but I can't seem to send the request with Java.

Accepted Solutions (0)

Answers (0)