com.android.volley.NoConnectionError:java.net.SocketException:sendto失败:EPIPE(管道破裂)

com.android.volley.NoConnectionError:java.net.SocketException:sendto失败:EPIPE(管道破裂),android,android-volley,Android,Android Volley,我有一个简单的任务,就是使用截击将一个base64编码的图像上传到服务器 我的服务器什么也不做。它只返回一个200状态码。但是,即使在服务器返回200之后,我也总是会出现这个错误。我在网上尝试了其他一些解决方案,但似乎没有任何效果 private void uploadImage(){ obj = new JSONObject(); try { obj.put("image", getStringImage(bitmap)); } catch (Excep

我有一个简单的任务,就是使用截击将一个base64编码的图像上传到服务器

我的服务器什么也不做。它只返回一个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;
}
private void uploadImage(){
obj=新的JSONObject();
试一试{
obj.put(“图像”,getStringImage(位图));
}捕获(例外e){
}
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Request.Method.POST,UPLOAD_URL,obj,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject JSONObject){
e(“来自服务器的消息”,jsonObject.toString());
Toast.makeText(getApplication(),“图像上传成功”,Toast.LENGTH_SHORT.show();
}
},new Response.ErrorListener(){
@凌驾
公共错误响应(截击错误截击错误){
Log.e(“来自服务器的消息”,volleyError.toString());
}
}) {
@凌驾
公共映射getHeaders()引发AuthFailureError{
Map headers=newhashmap();
返回标题;
}
};
add(jsonObjectRequest);
}
公共字符串getStringImage(位图bmp){
ByteArrayOutputStream bas=新的ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG,100,baos);
byte[]imageBytes=bas.toByteArray();
字符串encodedImage=Base64.encodeToString(imageBytes,Base64.DEFAULT);
返回图像;
}

我知道这已经晚了,但对我来说,解决方案是增加服务器中的http最大post大小。对我来说,我使用带嵌入式tomcat服务器的spring boot,因此解决方案是将以下行添加到你的
应用程序中。属性
文件:

server.tomcat.max-http-post-size=10000000
在上面,我已经将其设置为10MB,另一种方法是通过java代码,正如本文中的答案所指出的那样

希望对你有帮助