Android getResponseCode天气超时或读取响应
我有一个android应用程序,它可以将一些json数据上传到PHP脚本,PHP脚本将数据存储在数据库中Android getResponseCode天气超时或读取响应,android,sockets,timeout,httpurlconnection,Android,Sockets,Timeout,Httpurlconnection,我有一个android应用程序,它可以将一些json数据上传到PHP脚本,PHP脚本将数据存储在数据库中 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); try { connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("charset", "utf-8");
connection.setFixedLengthStreamingMode(bytes.length);
connection.setReadTimeout(3000000);
long tim = System.currentTimeMillis();
connection.getOutputStream().write(bytes);
connection.getOutputStream().flush();
if (connection.getResponseCode() != 200) {
long dur = System.currentTimeMillis() - tim;
String response = IOUtils.toString(connection.getInputStream(), "UTF-8");
throw new IOException(connection.getResponseCode() + " " + response);
}
} finally {
connection.disconnect();
}
数据到达脚本,脚本将数据存储到数据库中
当客户端上传大量数据时,请求大约需要15分钟,尽管它已经完成。数据完全写入数据库,php脚本发送响应
但是当它花费那么长的时间时,getResponseCode()函数永远不会返回。当我在调试器中点击pause时,它会显示以下堆栈:
知道出了什么问题吗
我正在API级别23上运行模拟器
似乎连接丢失了,但安卓没有检测到