Post 对服务器的请求无法正常工作 Volley

Post request to server not properly working Volley

大家好,我遇到了一个问题,问题是我正在尝试向服务器发送 post 请求,但出现异常

com.android.volley.ParseError: org.json.JSONException: 在

的字符 0 输入结束

当我尝试通过 get 请求发送数据时它工作正常,当我尝试通过 post 请求发送数据时出现上述异常我尝试搜索但未成功。 下面是我的代码

 JsonObjectRequest _send_cab_data_to_server = new JsonObjectRequest(Request.Method.POST,
            cab_Data_Url, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Log.e("", "response : " + response);

        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("", "error : " + error.toString());
        }
    }) {

        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Method", "CarLocation");
            params.put("data", _Cab_Locations_In_Driver_Service);
            return params;
        }

    };

    // Adding request to request queue
    Volley_Controller.getInstance().addToRequestQueue(_send_cab_data_to_server,
            "volley");


} 

而data属性对应的是一组组合的字符串 例如 Ï2|33.7129221|73.0634634|Apr28,201510:50:33AM|0Ï2|33.7129272|73.0634653|Apr28,201510:50:58AM|0È

并且 json 响应是

{ "Success": 是的, "Info": "Successful", "Response":[ { "Status": "Done" } ] }

when i try to send data through get request it is working properly and when i try to send data through post request i am getting the above exception

如您所说,您遇到了以下异常:

com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of

这意味着您收到了 null 回复。您应该只使用 GET 方法,而不是 POST 方法,因为您的服务器没有响应 post 请求,而是返回一个空对象,因此您的解析器在解析空对象时失败。

仅供参考,GET 和 POST 方法的意义和重要性。使用服务器定义的适当方法 API.