DDian_Ellen 2018-04-19 15:13 采纳率: 0%
浏览 685
已结题

用eclipse开发android,执行connect后系统不正常

执行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;
}
这一段的代码是这样,

  • 写回答

4条回答

  • s806616695 2018-04-19 17:10
    关注

    你这是获取流,那么会不会是你的网络异常呢?URL地址是否有误,又或者你应用没有申请网络权限?新手,请轻喷

    评论

报告相同问题?

悬赏问题

  • ¥60 Python如何后台操作Vmwake虚拟机键鼠
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容