2
我想從數據庫中獲取用戶的信息,並顯示它,但我不斷收到此錯誤:Android的凌空:BasicNetwork.performRequest:意外的響應代碼404
BasicNetwork.performRequest: Unexpected response code 404
這裏是我的javacode:
裝方法:
public void loadUserProfile() {
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
idTV.setText(jsonResponse.getString("_id"));
nameTV.setText(jsonResponse.getString("name"));
firstNameTV.setText(jsonResponse.getString("firstName"));
emailTV.setText(jsonResponse.getString("email"));
sexTV.setText(jsonResponse.getString("sex"));
yearTV.setText(jsonResponse.getString("year"));
cursusTV.setText(jsonResponse.getString("cursus"));
} catch (JSONException e) {
onLoadProfileFail();
}
}
};
ProfileRequest profileRequest = new ProfileRequest(user_id, responseListener);
RequestQueue queue = Volley.newRequestQueue(ProfileActivity.this);
queue.add(profileRequest);
}
Request類
class ProfileRequest extends StringRequest {
private static final String USER_PROFILE_REQUEST = "http://[ipaddress]:8080/users/:id";
private Map<String, String> params;
public ProfileRequest(String id, Response.Listener<String> listener) {
super(Method.POST, USER_PROFILE_REQUEST, listener, null);
params = new HashMap<>();
params.put("id", id);
}
@Override
public Map<String, String> getParams() {
return params;
}
}
個
app.js
router.get('/users/:id', function(req, res) {
User.find({ _id: "ie00847" }, function(err, user) {
if (err)
res.send(err);
res.json(user);
});
});