zoukankan      html  css  js  c++  java
  • android 127.0.0.1/localhost connection refused,在模拟器上应该用10.0.2.2访问你的电脑本机

    调试中通过android simulator模拟器链接localhost或者127.0.0.1,因为我在电脑上面建立了apache,我的代码大概就是
    URL url = new URL(urlString); 
        URLConnection urlconn = url.openConnection();

    但是报错了!!

    Exception 1:java.net.ConnectException: localhost/127.0.0.1:8080 - 
    Connection refused

    问题是这样的,android模拟器(simulator)把它自己作为了localhost,也就是说,代码中使用localhost或者127.0.0.1来访问,都是访问模拟器自己!这是不行的!

    如果你想在模拟器simulator上面访问你的电脑,那么就使用android内置的IP 10.0.2.2 吧,  10.0.2.2 是模拟器设置的特定ip,是你的电脑的别名alias

    记住,在模拟器上用10.0.2.2访问你的电脑本机

  • 相关阅读:
    人月神话读后感2
    大三学习进度13
    大三学习进度16
    大三学习进度14
    大三学习进度11
    大三学习进度15
    人月神话读后感3
    大三学习进度10
    Linux设备树
    clk_enable
  • 原文地址:https://www.cnblogs.com/abc8023/p/3760460.html
Copyright © 2011-2022 走看看