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