weixin_41342686
weixin_41342686
2019-04-29 19:53

android studio连接不上tomacte?

  • android-studio
  • android

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) {

            }
    }
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换