我想從REST API獲取JSON數據。如何從休息API獲取JSON數據
我寫了一個簡單的Java類作爲Jersey客戶端連接到Web服務,但是當我執行這個類時,他顯示的是HTML而不是JSON。 知道API是使用登錄名和密碼進行身份驗證的,我不知道如何處理。 這是我試圖編寫的類的源代碼。
{
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);
}
}
這將取決於,至少部分,在你試圖正是休息API與你交談,你忽略分享。 –
謝謝@Scott Hunter,它是一個API公司所有者,我試圖建立一個客戶球衣 API實現基本認證 –
我不明白是連接參數,我應該在頭部發送(queryparams() )還是有另一種解決方案 –