我正在尝试一次将多个 Json 字符串 [每个 1 MB] 发送到 PHP Server。当我尝试发送 10 条记录时,它工作正常。但如果它超过 20 条记录,它会说OutOfMemoryException
。我看到android内存大小限制t0 15MB - 16MB。但是没有任何线索如何解决这个问题,我正在使用下面的代码一次发送多条记录。
/** Upload Data*/
private void submitUploadData(String url, Map<String, String> param)
throws IOException {
URL siteUrl;
try {
siteUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) siteUrl
.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content1 = "";
Set getkey = param.keySet();
Iterator keyIter = getkey.iterator();
String content = "";
for (int i = 0; keyIter.hasNext(); i++) {
Object key = keyIter.next();
if (i != 0) {
content += "&"; //Crashing here
}
content += key + "=" + param.get(key); //Crashing here
System.out.println("Content" + content);
}
System.out.println(content);
out.writeBytes(content.trim());
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String jsonresponse = "";
while ((jsonresponse = in.readLine()) != null) {
System.out.println(jsonresponse);
if(!jsonresponse.equals("Authorisation Successful")){
updateUploadRecords(jsonresponse);}
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}