1

This is different from Jersey Client API - authentication

I need to call some REST API through Java program:

Originally I was calling API using below command:

curl https://xxx.xxx.com/api/xxx.json -v -u abc@gmail.com:XXX

Translated into Java, I got:

ClientConfig config = new DefaultClientConfig();
config.getClasses().add(MultiPartWriter.class);
Client client = Client.create(config);

client.addFilter(new HTTPBasicAuthFilter("abc@gmail.com", "XXX"));
return client.resource("https://xxx.xxx.com/api/xxx.json");

Everything works just fine. But later on, we need to call the API through token authentication rather than username/password.

The equivalent CURL command is:

 curl -u abc@gmail.com/token:ivtUYrVmVdpo3 https://xxx.xxx.com/api/xxx.json

How do I translate this into Java code??

Community
  • 1
  • 1
zdlgrj
  • 99
  • 1
  • 1
  • 9
  • I'm sorry but there is absolutely nothing different between the first command and the second, besides the ordering and that one has a verbose flag. They're both using Basic auth, just with different username (abc@gmail.com/token) and password (ivtUYrVmVdpo3). So _"How do I translate this into Java code??"_ - do the exact same thing you're currently doing, just change the username and password – Paul Samsotha May 05 '15 at 22:41

0 Answers0