com.android.volley.NoConnectionError:java.net.SocketException:sendto failed:EPIPE(Broken pipe)

时间:2016-07-25 06:52:28

标签: android android-volley

我有一个简单的任务,即使用Volley将基本64位编码图像上传到服务器。

我的服务器什么也没做。它只返回200状态代码。但即使在服务器返回200 之后,我总是会遇到此错误。我在网上尝试了其他一些解决方案,但似乎没有任何效果。

private void uploadImage(){
    obj = new JSONObject();
    try {
        obj.put("image", getStringImage(bitmap));
    } catch (Exception e) {

    }
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, UPLOAD_URL, obj,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject jsonObject) {
                    Log.e("Message from server", jsonObject.toString());
                    Toast.makeText(getApplication(), "Image Uploaded Successfully", Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Log.e("Message from server", volleyError.toString());
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<String, String>();
            return headers;
        }

    };
    requestQueue.add(jsonObjectRequest);
}

public String getStringImage(Bitmap bmp){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}

1 个答案:

答案 0 :(得分:1)

我知道这很晚了,但是对我来说,解决方案是增加服务器中的http max帖子大小。对我来说,我将Spring Boot与嵌入式tomcat服务器一起使用,因此解决方案是将以下行添加到您的{{ 1}}文件:

application.properties

以上我将其设置为10MB,另一种方法是通过此链接中答案所指向的Java代码 Increase HTTP Post maxPostSize in Spring Boot

希望对您有帮助