跪求:Android studio 连接不上Tomcate

       用myeclipse将项目部署在tomcate上,浏览器可以访问,android studio模拟器访问不了,也不报错
2.代码
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) {

            }
    }
}
查看全部
weixin_41342686
weixin_41342686
2019/04/29 19:34
  • java
  • android-studio
  • android
  • 点赞
  • 收藏
  • 回答
    私信

1个回复