使用null响应获取com.android.volley.servererror

时间:2017-06-27 07:22:36

标签: android android-volley

我想从图库上传照片。当我上传从相机从相机中捕获的图像时,会发生此错误。

凌空代码如下:

    StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Toast.makeText(upload.this,response, Toast.LENGTH_SHORT).show();
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {            error.printStackTrace();
                }
            }){
        protected Map<String,String> getParams()
        {
            Map<String,String> params = new HashMap<String, String>();

            params.put("photo",str_photo);
            params.put("title",str_caption);
            params.put("name",str_caption);
            params.put("admin_id",admin_id);
            return params;
        }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(upload.this);
    requestQueue.add(stringRequest);

logcat如下

06-28 10:24:43.442 8774-10428/laurel.wedding E/Volley: [1802] BasicNetwork.performRequest: Unexpected response code 413 for http://teachieparentine.com/Wedding_App/photo_upload.php

2 个答案:

答案 0 :(得分:0)

您可以按照以下链接使用多部分使用排球上传图片...

How to upload Image on server using Volley?

答案 1 :(得分:0)

在onErrorResponse()函数中添加它,并更新帖子

error.printStackTrace()