Android 使用ksoap2将大小为5 mb的字节数组传递给web服务时出现内存不足错误
我已将我的DB文件转换为字节数组,并希望将其传递给我的web服务,以便在服务器上保存。我的数据库大小为5MB,但当添加到soap_请求时,它会出现内存不足的异常…我正在附加我的代码,如下所示Android 使用ksoap2将大小为5 mb的字节数组传递给web服务时出现内存不足错误,android,ksoap2,android-ksoap2,Android,Ksoap2,Android Ksoap2,我已将我的DB文件转换为字节数组,并希望将其传递给我的web服务,以便在服务器上保存。我的数据库大小为5MB,但当添加到soap_请求时,它会出现内存不足的异常…我正在附加我的代码,如下所示 File file = new File(filePath); int size = (int) file.length(); byte[] bytes = new byte[size]; Log.v(TAG,
File file = new File(filePath);
int size = (int) file.length();
byte[] bytes = new byte[size];
Log.v(TAG, "File size in byte ==>"+size);
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
Log.v(TAG, "ByteArray = "+bytes.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
SoapObject soap_request = new SoapObject(NAMESPACE, METHOD_NAME);
fileName = "TraceBaleAndroid_"+UserID+"_"+backupDateTime+".db";
Log.v(TAG, "FileName = "+fileName);
soap_request.addProperty("_FileName", fileName);
soap_request.addProperty("_ByteArray",bytes);
soap_request.addProperty("UserID", UserID);
Log.v(TAG, "soap_request _FileName= >>"+soap_request.getProperty(0));
//Log.v(TAG, "soap_request _ByteArray= >>"+soap_request.getProperty(1));
Log.v(TAG, "soap_request UserID= >>"+soap_request.getProperty(2));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(envelope);
envelope.setOutputSoapObject(soap_request);
envelope.dotNet = true;
Log.v(TAG,"Calling webservice....");
androidHttpTransportSE = new HttpTransportSE(URL);
androidHttpTransportSE.debug = true;
androidHttpTransportSE.call(SOAP_ACTION, envelope);
Log.v(TAG,"Getting result from webservice....");
SoapObject result = (SoapObject) envelope.bodyIn;
JSONObject response = new JSONObject(result.getProperty(0).toString());
Log.v(TAG, "Web Response...." + response.get(" Result "));
if (response.get(" Result ").equals("Uploading DataBase Backup To Server successfully"))
{
flag = true;
Log.v(TAG, "Database is uploaded .........");
}
} catch (Exception e) {
e.printStackTrace();
}
finally
{
androidHttpTransportSE.reset();
}
具有5MB数据的SOAP请求在我看来真的很奇怪。但如果您确实确定需要,请检查此问题的答案:
所有这些建议对您的情况也是有效的。我将尝试此方法,如果您知道将此字节数组发送到web服务的任何其他方法,请建议我,因为我是新手,在这方面没有做太多工作……提前感谢,实际上我的字节数组大小为5345280,但出现类似“16035856字节分配内存不足”的错误在我的例子中,android:largeHeap=true不起作用……我通常不使用KSOAP来代替HTTPGET或POST@Narendra,按照Ashish Jani的建议使用HTTP POST。@AndreyVoitenkov如何使用HTTP POST调用特定的web服务方法,因为我们可以使用KSOAP调用特定的方法。如果可能,请相应地修改我的代码……我搜索了HTTP POST,但没有获得如何调用该特定方法的信息。。谢谢