执行conn.connect()之后的try,就直接throw e;然后执行conn.disconnect();
之后程序就死掉了
我确定我的电脑手机都在同一网域下,debug的时候出现这个问题:
Attempting to connect debugger to 'com.example.gdzc' on port 8600
这个怎么破。。。
程序如下:
public static String post(String urlStr, String paramsStr) throws Exception {
byte[] data = paramsStr.getBytes();
URL url = null;
HttpURLConnection conn = null;
InputStream inStream = null;
String response = null;
try {
url = new URL(urlStr);
conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(TIME_OUT);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod(METHOD_POST);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", CHARTSET);
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.connect();
DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream());
outputStream.write(data);
outputStream.flush();
outputStream.close();
int responseCode = conn.getResponseCode();
if (responseCode == HTTP_OK) {
inStream = conn.getInputStream();
response = getResponse(inStream);
} else {
response = "return" + responseCode;
}
} catch (Exception e) {
throw e;
} finally {
conn.disconnect();
}
return response;
}
这一段的代码是这样,
你这是获取流,那么会不会是你的网络异常呢?URL地址是否有误,又或者你应用没有申请网络权限?新手,请轻喷
我以前写一个套接字无人机控制应用时也是这样,直接就崩了,一直找不到什么原因,后来发现是我以为自己写过权限了所以没检查,很二的经历
看一下权限 要是有权限就另说 还有 为啥 不用AS啊
干脆下载个模拟器
雷电模拟器 端口号5555
天天模拟器 端口号6555
然后写个.bat批处理文件,connect命令
网上有~直接搜