上传图片为Base64字符串,带有空射返回警告:LogSlowRequest


Upload picture as Base64 string with volley returns warning: LogSlowRequest

我想从我的应用程序上传图片到服务器。因为ftp连接是不可能的,我想上传图片作为请求与POST。

我使用volley为我的应用程序。当我将pic转换为Base64字符串并将其发送到我的服务器时,我得到警告:

D/Volley: [50697] BasicNetwork。logSlowRequests: HTTP响应[] http://domain.com/api.php 0x3ce314bb NORMAL 1>[一生= 5264],[size = 2], [rc = 200], [retryCount = 0]

这是我的上传类:

public class Upload {
    private Context context;
    public Upload(Context _context){
        context = _context;
    }
    public void upload(final File file){
        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest sr = new StringRequest(Request.Method.POST,"http://domain.com/api.php", new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("DEBUG","RESPONSE: " + response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {}
        }){
            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<>();
                params.put("a","text");
                params.put("b",convertPic(file.getPath()));
                params.put("c","text");
                return params;
            }
        };
        queue.add(sr);
    }
    private String convertPic(String path)
    {
        Bitmap bitmap = BitmapFactory.decodeFile(path);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, baos);
        byte[] b = baos.toByteArray();
        return Base64.encodeToString(b, Base64.DEFAULT);
    }
    private String convertString(String s){
        return Base64.encodeToString((s).getBytes(),Base64.NO_WRAP);
    }
}
对于测试,我的php脚本只是检查$_POST字段:
<?php
    header('content-type: text/plain; charset=utf-8');
    header("access-control-allow-origin: *");
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    $post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
    if(isset($post['a']) && $post['a'] != "" && isset($post['b']) && $post['b'] != "" && isset($post['c']) && $post['c'] != ""){
        echo 'OK';
    }

添加重试:

sr.setRetryPolicy(new DefaultRetryPolicy(0,0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

: DefaultRetryPolicy。DEFAULT_MAX_RETRIES to 0