2
我送這樣的如何使用Android中的Volley發送Post請求?
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//submitForm();
JsonObjectRequest jsonobjectRequest = new JsonObjectRequest(Request.Method.POST, URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//errorlabel.setText(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
errorlabel.setText("Invalid username/password");
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("email", "[email protected]");
params.put("password", "asd");
return params;
}
};
errorlabel.setText(jsonobjectRequest.toString());
requestQueue.add(jsonobjectRequest);
}
});
}
凌空請求,但我從服務器上說無效的電子郵件/密碼,得到一個錯誤信息。
我已經設置了正確的參數。我在郵差上測試了它,並且在那裏工作。這是一個截圖。
截圖
你可以嘗試用StringRequest? –
JSONObject請求中存在一個錯誤,你不能發送參數:https://stackoverflow.com/questions/19837820/volley-jsonobjectrequest-post-request-not-working, 你需要嘗試使用StringRequest,它肯定會工作。 –
與字符串請求一起工作。如果你把它作爲答案發布,我可以接受它。 – Nee