我在自己的电脑上用tomcat架设了web服务器,服务器里设置了相应的jsp,然后用HttpURLConnection链接web服务器,代码如下
try {
URL url = new URL("http", "192.168.0.105", 8080,
"/login.jsp?id=huzhiheng&password=123456&table=user");// 连接地址
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
byte [] data = new byte[512] ; // 开辟空间
int len = conn.getInputStream().read(data); // 接收数据
if(len > 0){
String temp = new String(data,0,len).trim() ;
Log.v("test",temp);
flag = Boolean.parseBoolean(temp); // 数据转型
info.setText(temp) ;
}
conn.getInputStream().close() ; // 关闭输入流
} catch (Exception e) {
e.printStackTrace() ;
info.setText("登陆服务器失败!");
}
在虚拟机上正常运行,在手机上就不行了直接出错登录失败
我在手机浏览器上输入地址192.168.0.105:8080/login.jsp?id=huzhiheng&password=123456&table=user
也能显示正确数据
苦等各位大神指教啊android,web服务,
try {
URL url = new URL("http", "192.168.0.105", 8080,
"/login.jsp?id=huzhiheng&password=123456&table=user");// 连接地址
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
byte [] data = new byte[512] ; // 开辟空间
int len = conn.getInputStream().read(data); // 接收数据
if(len > 0){
String temp = new String(data,0,len).trim() ;
Log.v("test",temp);
flag = Boolean.parseBoolean(temp); // 数据转型
info.setText(temp) ;
}
conn.getInputStream().close() ; // 关闭输入流
} catch (Exception e) {
e.printStackTrace() ;
info.setText("登陆服务器失败!");
}
在虚拟机上正常运行,在手机上就不行了直接出错登录失败
我在手机浏览器上输入地址192.168.0.105:8080/login.jsp?id=huzhiheng&password=123456&table=user
也能显示正确数据
苦等各位大神指教啊android,web服务,
解决方案 »
- systemUI wifi图标更改
- Andriod中JNI调用C函数,根据JNI的规范封装的C函数,其它package就无法再使用了,对吗?
- 请问下,我这个布局为什么只能显示上面的部分,不能显示下面的button呢?
- Android NDK
- 求教使用Paint.drawText的细节问题
- android 菜单制作
- Android 代码 可是设置呼叫转移么?
- 有没有这样的方法String.format("aaa%d, bbb%d, ccc%d", "我","你", “他”);
- 在线跪等!!求大神帮忙看看!!!!
- android MapView 转成 Bitmap
- 为什么AlertDialog中加入的输入框EditText中的字体有时候很小呢?
- 新老朋友,都来瞧瞧!
如果是的话,检查一下,你们WIFI是否可以连通局域网? 比如你用台笔记本电脑用WIFI连网,然后去PING你的主机,看看能不能PING通。如果不是用WIFI联网,那么你必须得有服务器的公网IP才能连通。