I want to get JSON data from a REST API.
I wrote a simple Java class as Jersey client to connect to the web service but when I execute the class, he displays HTML, not JSON. knowing that the API is authentication with login and password and I don't know how I process. Here is the source code for the class I tried to write.
{
public class RestClient {
public static void main(String ar[]) throws Exception
{
String baseUrl="??????????????";
String password="???????????";
String user="?????????";
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(baseUrl);
service.path("j_spring_security_check");
service.queryParam("j_username", user);
service.queryParam("j_password", user);
service.queryParam("ajax", "true");
String out = service.accept(MediaType.APPLICATION_JSON).get(String.class);
System.out.println(out);
}
}