【问题标题】:Connecting an android phone to a server over http and outputstream通过 http 和 outputstream 将安卓手机连接到服务器
【发布时间】:2013-08-27 16:26:15
【问题描述】:

我正在尝试通过 http 将 android 手机连接到在我的本地计算机上运行的服务器并输出内容但不成功..!

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {

        URL url = new URL("http://192.168.24.42:80/DebugServer/");
        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();     
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        readStream(in);
        urlConnection.disconnect();

    } catch (IOException e) {
        e.printStackTrace();
}


private void readStream(InputStream in) {

    try {
        in.read();
        in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

  • 您有问题吗?
  • 你得到什么错误?
  • 你应该连接到端口 8080 吗???

标签: android apache http


【解决方案1】:
URL url = new URL("http://192.168.24.42:80/DebugServer/");  

是您的连接 URL。将端口更改为8080,因为这是服务器监听的地方。

另外,你有没有去你的tomcatbin 文件夹(我在这里假设)并运行startup.BATstartup.SH 文件,因为没有那个你的服务器没有运行。

要检查您的服务器是否正常运行,请尝试http://localhost:8080
请发布 logcat :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 2011-01-02
    相关资源
    最近更新 更多