我正在使用一个简单的main方法java类来调用一个restful URL来使用该应用程序。我创建了一个客户端并试图调用该URL。我的问题是:如何添加json数据作为查询参数?以下是我的方法。如何将json数据添加到客户端url
public static void main(String[] args) {
try {
Client client = Client.create();
WebResource webResource = client.resource("http://10.123.85.120:8080/myWebService/updateModel.do?abc=33589&applicationId=8&uuid=9a26038f-6dd1-40b6-b847-f2fd16366fc0&jsonData={"NostudentsOrganized": 1,"Noofcourses": 20,"Noofattendedstudents": 5}");
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
你想查询参数添加到另一台服务器的呼叫? –
不,在这里我得到编译时error.please在这里修改url – Sthogari
啊对不起,没有看到其余的查询字符串 –