weixin_41342686
2019-04-29 19:39跪求:Android studio连接tomcate
1.myeclipae将项目部署在tomacate上,浏览器可以访问,Android模拟器访问不了,也不报错
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void loginClick(View v) {
String path = "http://10.0.2.2:8080/Demo1/Servlet1";
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setConnectTimeout(5000);
int code = connection.getResponseCode();
if (code == 200) {
Toast.makeText(getApplicationContext(),"成功",Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
}
}
}
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- AndroidStudio基础项目Sync过慢
- android-studio
- 1个回答
- android studio 可以build但run会报错
- android-studio
- android
- 3个回答
- 将Android Studio连接到Web服务到SQL Server
- android
- php
- 1个回答
- 用android studio打包apk出现错误提示
- android-studio
- java
- android
- 1个回答
- idea 写flutter app,重启电脑后项目便宜报错Error:Android Dex: [my_app] Unable to execute DX
- android-studio
- android
- 2个回答
换一换