我想寫一個讓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();
} |