我做了一个小应用程序。我做了登录申请。我想从动作类调用宁静的网络服务。我使用了struts2框架。我不能改变宁静的网络服务。请给我建议。
问问题
5836 次
1 回答
3
这是我的问题的解决方案。
try {
URL url = new URL("http://localhost:8080/ProWebservices/webresources/users/" + emailid + "&" + password + "&photographer");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
JsonObject json = (JsonObject) new JsonParser().parse(output);
String out = (String) json.get("userid").toString();
if(!out.equals("null")){
return "SUCCESS";
}
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
于 2013-10-18T11:15:39.367 回答