安卓3G网络调用JSP页面失败

leeyeefeng2004 2014-07-29 04:54:13
环境与现象如下:

1、在App中已设置了<uses-permission android:name="android.permission.INTERNET"/>这个配置
2、App代码中使用POST方法和 HttpURLConnection 类
3、使用IE等浏览器能成功通过外网IP+端口访问指定JSP页面
4、经过跟踪这段代码出现了 conn.getInputStream(); 异常,为什么?

问题1:服务器端使用了jsp页面,使用WIFI能成功请求并返回结果,为什么我切换至3G移动数据网络不能访问啊?
问题2:是否有其他配置方面的遗漏?
问题3:HTTP头部是否正确呢?以下是我头部:
URL url = new URL(_url);
conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("content-type", "text/html");
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);

conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
conn.setRequestProperty("Content-type", "text/html");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setRequestMethod("POST");


...全文
142 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lionfresh 2014-07-29
  • 打赏
  • 举报
回复
引用 2 楼 leeyeefeng2004 的回复:
java.net.ConnectException: failed to connect to /我的外网IP(port 端口): connect failed: ENETUNREACH (Network is unreachable)
你的3G网络是否可用呢?3G网络下能通过浏览器访问你的页面吗?
leeyeefeng2004 2014-07-29
  • 打赏
  • 举报
回复
java.net.ConnectException: failed to connect to /我的外网IP(port 端口): connect failed: ENETUNREACH (Network is unreachable)
Birds2018 2014-07-29
  • 打赏
  • 举报
回复
什么异常? 除非你服务器进行了特殊的判断,一般不用加这些东西。 conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); conn.setRequestProperty("Content-type", "text/html"); conn.setRequestProperty("Accept-Charset", "utf-8"); conn.setRequestProperty("contentType", "utf-8"); conn.getInputStream(); 这个异常贴出来就知道问题了。

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧