Android Volley POST发送参数始终为null

Android Volley POST发送参数始终为null,第1张

概述我是 android的新手.现在我正在做一个应用程序.对于这个我需要将数据发送到server.Now我正在使用Volley post方法.但是当我使用volley.here发送数据到服务器时,参数总是显示为null附上代码请检查.我在使用片段. 代码部分 String url = "http://192.168.1.182:8084/name/registration.jsp"; fin 我是 android的新手.现在我正在做一个应用程序.对于这个我需要将数据发送到server.Now我正在使用Volley post方法.但是当我使用volley.here发送数据到服务器时,参数总是显示为null附上代码请检查.我在使用片段.

代码部分

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","[email protected]");            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","[email protected]");    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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1130057.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存