简体   繁体   English

BasicNetwork.performRequest:意外的响应代码413?

[英]BasicNetwork.performRequest: Unexpected response code 413?

i want to submit an array to my server through the following method. 我想通过以下方法向我的服务器提交一个数组。 my array also contain images in string format(encoded in string format). 我的数组还包含字符串格式的图像(以字符串格式编码)。 without images string it work for me. 没有图像的字符串对我有用。 but when i add string encoded images it give the following error: 但是当我添加字符串编码的图像时,会出现以下错误:

  • E/Volley: [4084] BasicNetwork.performRequest: Unexpected response code 413 for http://www.......com/TrueCaller/submit_contacts.php 05-21 14:37:38.643 18773-18773/satsuma.callerid_realcaller W/System.err: com.android.volley.ClientError 05-21 14:37:38.644 18773-18773/satsuma.callerid_realcaller W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:190) 05-21 14:37:38.644 18773-18773/satsuma.callerid_realcaller W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120) 05-21 14:37:38.644 18773-18773/satsuma.callerid_realcaller W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)* E / Volley:[4084] BasicNetwork.performRequest: http://www.......com/TrueCaller/submit_contacts.php 05-21 14:37:38.643 18773-18773 / satsuma.callerid_realcaller的意外响应代码413 W / System.err:com.android.volley.ClientError 05-21 14:37:38.644 18773-18773 / satsuma.callerid_realcaller W / System.err:在com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java :190)05-21 14:37:38.644 18773-18773 / satsuma.callerid_realcaller W / System.err:位于com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)05-21 14:37:38.644 18773 -18773 / satsuma.callerid_realcaller W / System.err:at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)*
        private void submitContacts(){

        // now here we convert this list array into json string

        Gson gson=new Gson();

        final String newDataArray=gson.toJson(dataArray); // dataarray is list aaray

        final String server_url="http://www.........com/TrueCaller/submit_contacts.php"; // url of server check this 100 times it must be working



        // volley

        StringRequest stringRequest=new StringRequest(Request.Method.POST, server_url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response)
                    {

                        final String result=response.toString();
                        Log.d("response", "result : "+result); //when response come i will log it
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error)
                    {
                        error.printStackTrace();
                        error.getMessage(); // when error come i will log it
                    }
                }
        )
        {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> param=new HashMap<String, String>();
                param.put("array",newDataArray); // array is key which we will use on server side

                return param;
            }
        };
        Vconnection.getnInstance(this).addRequestQue(stringRequest); // vConnection i claas which used to connect volley

    }

array initialisation: 数组初始化:

 if (phoneC != "") {
                Bitmap bitmap = retrieveContactPhoto(MainActivity.this, phoneC);
                String image = "";
                if (bitmap != null) {
                    image = getStringImage(bitmap);
                }

                Contact_Details dt = new Contact_Details(name, phoneC, UIDD, country_code, image, emailC, adressC);
                dataArray.add(dt);
            }

Contact_Details class is below: Contact_Details类如下:

public class Contact_Details {
String name;
String phone_no;
String identifier;
String country_code;

public String getCountry_code() {
    return country_code;
}

public void setCountry_code(String country_code) {
    this.country_code = country_code;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}

String image;

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

String email;

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

String address;

public Contact_Details(String name, String phone_no, String identifier, String country_code, String image, String email, String address) {
    this.name = name;
    this.phone_no = phone_no;
    this.identifier = identifier;
    this.country_code = country_code;
    this.image = image;
    this.email = email;
    this.address = address;
}


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getPhone_no() {
    return phone_no;
}

public void setPhone_no(String phone_no) {
    this.phone_no = phone_no;
}

public String getIdentifier() {
    return identifier;
}

public void setIdentifier(String identifier) {
    this.identifier = identifier;
}
}

Is it absolutely necessary to send the array of Contact_Details to the server? 是否必须将Contact_Details数组发送到服务器? is there a solution to just send one object of Contact_Details ? 有一种解决方案,只发送一个Contact_Details对象?

413 error is Payload Too Large . 413错误是Payload Too Large More on that error here 有关此错误的更多信息,请点击此处

Please also verify that Bitmap image to Base64 String conversion is working. 另请验证位图图像Base64字符串的转换是否正常。

You can use the following class to do just that: 您可以使用以下类来做到这一点:

public class ImageUtil {
public static Bitmap convert(String base64Str) throws IllegalArgumentException {
    byte[] decodedBytes = Base64.decode(
            base64Str.substring(base64Str.indexOf(",") + 1),
            Base64.DEFAULT
    );

    return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
}

public static String convert(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

    return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
}

}

Other than that you can check on the server side to see if the database supports strings of Base64 length. 除此之外,您还可以在服务器端检查数据库是否支持Base64长度的字符串。

below code is for array uploading to server: 下面的代码用于将数组上传到服务器:

private void submitContacts() {


    // now here we convert this list array into json string

    Gson gson = new Gson();

    final String newDataArray = gson.toJson(dataArray); // dataarray is list aaray

    final String server_url = "http://www.vvvv.com/Caller/submit_contacts.php"; // url of server check this 100 times it must be working


    // volley

    StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    final String result = response.toString();
                    Log.d("response", "result : " + result); //when response come i will log it
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    error.getMessage(); // when error come i will log it
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> param = new HashMap<String, String>();
            param.put("array", newDataArray); // array is key which we will use on server side

            return param;
        }
    };
    Vconnection.getnInstance(this).addRequestQue(stringRequest); // vConnection i claas which used to connect volley


}

code of Vconnection class is below: Vconnection类的代码如下:

public class Vconnection {

private static Vconnection nInstance;
private RequestQueue RQ;
private Context CTX;

private Vconnection(Context context)
{
    CTX=context;
    RQ=getRequestQue();

}

public RequestQueue getRequestQue()
{
    if(RQ==null)
    {
        RQ= Volley.newRequestQueue(CTX.getApplicationContext());
    }
    return RQ;
}
public static synchronized Vconnection getnInstance(Context context)
{
    if(nInstance==null)
    {
        nInstance=new Vconnection(context);
    }
    return nInstance;
}
public <T> void addRequestQue(Request<T> request)
{
    int socketTimeout = 30000;
    RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    request.setRetryPolicy(policy);
    RQ.add(request);
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BasicNetwork.performRequest:意外的响应代码500 - BasicNetwork.performRequest: Unexpected response code 500 BasicNetwork.performRequest:意外的响应代码422 - BasicNetwork.performRequest: Unexpected response code 422 BasicNetwork.performRequest:意外的响应代码400(GET) - BasicNetwork.performRequest: Unexpected response code 400 (GET) Volley - BasicNetwork.performRequest:意外的响应代码400 POST - Volley - BasicNetwork.performRequest: Unexpected response code 400 POST E / Volley:[126] BasicNetwork.performRequest:意外的响应代码500 - E/Volley: [126] BasicNetwork.performRequest: Unexpected response code 500 Volley BasicNetwork.performRequest:意外的响应代码 301 - Volley BasicNetwork.performRequest: Unexpected response code 301 BasicNetwork.performRequest:意外的响应代码500 Android - BasicNetwork.performRequest: Unexpected response code 500 Android Android Volley:BasicNetwork.performRequest:意外的响应代码404 - Android Volley: BasicNetwork.performRequest: Unexpected response code 404 E / Volley:[145] BasicNetwork.performRequest:https://的意外响应代码404 - E/Volley: [145] BasicNetwork.performRequest: Unexpected response code 404 for https:// 如何修复“Volley:[15771] BasicNetwork.performRequest:Android 中的意外响应代码 404? - How to fix "Volley: [15771] BasicNetwork.performRequest: Unexpected response code 404 in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM