Java BasicNetwork.performRequest:意外响应代码413?
我想通过以下方法向我的服务器提交一个数组。我的数组还包含字符串格式的图像(以字符串格式编码)。没有图像字符串,它对我有用。但当我添加字符串编码的图像时,会出现以下错误:Java BasicNetwork.performRequest:意外响应代码413?,java,android,android-volley,http-status-code-413,Java,Android,Android Volley,Http Status Code 413,我想通过以下方法向我的服务器提交一个数组。我的数组还包含字符串格式的图像(以字符串格式编码)。没有图像字符串,它对我有用。但当我添加字符串编码的图像时,会出现以下错误: E/Volley:[4084]基本网络。性能请求:的意外响应代码413 05-21 14:37:38.643 18773-18773/温州蜜柑 W/System.err:com.android.volley.ClientError 05-21 14:37:38.644 18773-18773/satsuma.callerid_
- E/Volley:[4084]基本网络。性能请求:的意外响应代码413 05-21 14:37:38.643 18773-18773/温州蜜柑 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/温州蜜柑 W/System.err:at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120) 05-21 14:37:38.644 18773-18773/温州蜜柑 W/System.err:at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)*
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;
}
}
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);
}
是否绝对有必要将
联系人详细信息数组发送到服务器?是否有只发送一个联系人详细信息对象的解决方案
413
错误是负载太大
。更多关于这个错误的信息
还请验证位图图像到Base64字符串的转换是否正常
您可以使用以下类来完成此操作:
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);
}
}
除此之外,您可以在服务器端检查数据库是否支持Base64长度的字符串。下面的代码用于将数组上载到服务器:
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
}
private void submitContacts(){
//现在我们将这个列表数组转换成json字符串
Gson Gson=新的Gson();
最后一个字符串newDataArray=gson.toJson(dataArray);//dataArray是list-aaray
最终字符串服务器\u url=”http://www.vvvv.com/Caller/submit_contacts.php“;//服务器的url检查100次,它必须正常工作
//截击
StringRequest StringRequest=新的StringRequest(Request.Method.POST、服务器url、,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
最终字符串结果=response.toString();
Log.d(“响应”,“结果:+result);//当响应到来时,我将记录它
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
错误。printStackTrace();
error.getMessage();//当出现错误时,我将记录它
}
}
) {
@凌驾
受保护的映射getParams()引发AuthFailureError{
Map param=new HashMap();
put(“array”,newDataArray);//array是我们将在服务器端使用的键
返回参数;
}
};
Vconnection.getnInstance(this.addRequestQue(stringRequest);//用于连接截击的Vconnection i claas
}
V连接等级代码如下:
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;
}
}
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);
}
公共类Vconnection{
专用静态连接实例;
专用请求队列RQ;
私有上下文CTX;
专用Vconnection(上下文)
{
CTX=上下文;
RQ=getRequestQue();
}
公共请求队列getRequestQueue()
{
如果(RQ==null)
{
RQ=Volley.newRequestQueue(CTX.getApplicationContext());
}
返回RQ;
}
公共静态同步Vconnection getnInstance(上下文)
{
如果(n实例==null)
{
n实例=新的Vconnection(上下文);
}
返回实例;
}
公共无效addRequestQue(请求)
{
int socketTimeout=30000;
RetryPolicy policy=新的DefaultRetryPolicy(socketTimeout,DefaultRetryPolicy.DEFAULT\u MAX\u RETRIES,DefaultRetryPolicy.DEFAULT\u BACKOFF\u MULT);
request.setRetryPolicy(策略);
RQ.添加(请求);
}
}