標題:
Java jersey接收回傳參數問題
[列印本頁]
作者:
google115177165
時間:
2015-7-30 23:22
標題:
Java jersey接收回傳參數問題
我想寫一個讓Android能做登入功能的Server
以下是我Server 的原始碼 我是用Google的Postman POST一個Json
但卻都沒有反應,不知道問題是出在哪裡
@POST
@Path("/users/login")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String login(InputStream is)throws JSONException {
StringBuffer buffer = null;
if (is != null) {
buffer = new StringBuffer();
try {
Reader in = new BufferedReader(
new InputStreamReader(is,"UTF-8"));
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
} catch (IOException e) {
return null;
}
} else {
return null;
}
JSONObject requestBodyJson = new JSONObject(buffer.toString());
String username = requestBodyJson.getString("username");
String password = requestBodyJson.getString("password");
if(username.equals("jerseyuser") && password.equals("jerseypass")){
return new JSONObject().put("statuscode",200).toString();
}else{
return new JSONObject().put("statuscode",500).toString();
}
作者:
codedata
時間:
2015-7-31 09:47
單只有這樣看不出什麼,在 catch IOException 之後,也沒有輸出任何錯誤訊息,只是 return null 而已,這種吞掉 exception 是最糟的寫法。
歡迎光臨 CodeData 技術論譠 (http://www.codedata.com.tw/forum/)
Powered by Discuz! 7.2