0

I'm trying does a request http in the Cloudant, but I receiving "Unauthorized".

HttpsURLConnection conn;
URL url = new URL(MyURL+"/_all_dbs");    
conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();

The curious, it's that with curl in terminal this works! Like:

curl 'MyURL/_all_dbs' -X GET

this works fine! And I receiving a list of my databases. But in the Java code not, I receiving 401 error. Also, I can't using the library Cloudant-Client because other problems ocurrs and I need this working with HTTP because will serve for other application that must only HTTP request.

Augusto
  • 3,825
  • 9
  • 45
  • 93
  • 1
    Don't include your authentication credentials in your URL e.g. `https://$ACCOUNT:$PASSWORD@$ACCOUNT.cloudant.com/_all_dbs`. Take a look at https://stackoverflow.com/questions/7019997/preemptive-basic-auth-with-httpurlconnection for an example on how to add the Basic Authentication header to your request. – ptitzler Jun 13 '17 at 17:13

1 Answers1

0

The HTTP 401 Unauthorized client error status response code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. you can execute terminal command using java code.

Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17