代码部分
String url = "http://192.168.1.182:8084/name/registration.Jsp"; final ProgressDialog pDialog = new ProgressDialog(this.getActivity()); pDialog.setMessage("Loading..."); pDialog.show(); RequestQueue rq = Volley.newRequestQueue(getActivity().getApplicationContext()); JsonObjectRequest JsonObjReq = new JsonObjectRequest(Method.POST,url,null,new Response.Listener<JsONObject>() { @OverrIDe public voID onResponse(JsONObject response) { Log.d(TAG,response.toString()); // pDialog.hIDe(); } },new Response.ErrorListener() { @OverrIDe public voID onErrorResponse(VolleyError error) { VolleyLog.d(TAG,"Error: " + error.getMessage()); //pDialog.hIDe(); } }) { @OverrIDe protected Map<String,String> getParams() { Map<String,String> params = new HashMap<String,String>(); params.put("name","Ajay K K"); params.put("mailID","ajaykk50@gmail.com"); params.put("phone","8086327023"); params.put("place","Calicut"); params.put("longitude","44444.3333"); params.put("latitude","666666.3333"); params.put("wheel","1"); params.put("type","owner"); return params; } }; // Adding request to request queue rq.add(JsonObjReq);解决方法 不要覆盖getParams(). JsonObjectRequest使用构造函数中的第三个参数来获取post参数.以下是凌空代码中包含的文档
/** * Creates a new request. * @param method the http method to use * @param url URL to fetch the JsON from * @param JsonRequest A {@link JsONObject} to post with the request. Null is allowed and * indicates no parameters will be posted along with request. * @param Listener Listener to receive the JsON response * @param errorListener Error Listener,or null to ignore errors. */public JsonObjectRequest(int method,String url,JsONObject JsonRequest,Listener<JsONObject> Listener,ErrorListener errorListener) { super(method,(JsonRequest == null) ? null : JsonRequest.toString(),Listener,errorListener);}
像这样使用.
String url = "http://192.168.1.182:8084/name/registration.Jsp";final ProgressDialog pDialog = new ProgressDialog(this.getActivity());pDialog.setMessage("Loading...");pDialog.show(); RequestQueue rq = Volley.newRequestQueue(getActivity().getApplicationContext());JsONObject params = new JsONObject();try { params.put("name","Ajay K K"); params.put("mailID","ajaykk50@gmail.com"); params.put("phone","8086327023"); params.put("place","Calicut"); params.put("longitude","44444.3333"); params.put("latitude","666666.3333"); params.put("wheel","1"); params.put("type","owner");} catch (JsONException e) { e.printstacktrace();}JsonObjectRequest JsonObjReq = new JsonObjectRequest(Method.POST,params,//Not null. new Response.Listener<JsONObject>() { @OverrIDe public voID onResponse(JsONObject response) { Log.d(TAG,response.toString()); // pDialog.hIDe(); }},new Response.ErrorListener() { @OverrIDe public voID onErrorResponse(VolleyError error) { VolleyLog.d(TAG,"Error: " + error.getMessage()); //pDialog.hIDe(); }});// Adding request to request queuerq.add(JsonObjReq);总结
以上是内存溢出为你收集整理的Android Volley POST发送参数始终为null全部内容,希望文章能够帮你解决Android Volley POST发送参数始终为null所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)