【发布时间】:2015-04-02 22:11:47
【问题描述】:
我在我的 Android 项目中使用 Volley 将其连接到服务器。
我需要使用post 方法将数据发送到 url 并获得响应,但 volley 不传递我的数据。
这是我的代码:
StringRequest jsonObjReq = new StringRequest(Request.Method.POST,url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jres=new JSONObject();
jres.opt(response);
if(jres.getString("value").toLowerCase()=="true"){
ConfirmMob=txtMob.getText().toString();
SubmitMob();
}
else{
AlertDialog.Builder dialog=new AlertDialog.Builder(App.getContext());
dialog.setMessage(R.string.IncorrectMob);
dialog.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
loading.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("IsMobValid - " + error.networkResponse, "Error: " + error.getMessage());
error.printStackTrace();
error.networkResponse
loading.hide();
}
}){
@Override
protected Map<String,String> getParams()throws AuthFailureError{
Map<String,String> params = new HashMap<String, String>();
params.put("x", "IsMobValid");
params.put("Mob", txtMob.getText().toString());
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded");
return params;
}
};
App.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
如何修复它以使其正常工作? 有什么问题吗?
【问题讨论】:
-
你有没有收到任何错误信息
onErrorResponse? -
没有@yaa110。在服务器端发生错误,因为请求需要一些参数,但在我的请求 volley 中不要将它们发送到服务器
-
你启动请求队列了吗?
-
在上面代码的最后一行,当请求添加到 requestQueue 时,请求开始@ElDuderino
标签: android http-post android-volley