![](/img/trans.png)
[英]Why can't I connect my Android device to localhost using the Intel XDK app?
[英]Why can't my app connect to localhost with easyphp devserver?
我正在制作一個 android 應用程序,該應用程序從 web 頁面檢索信息。 簡而言之,有代碼:
protected Void doInBackground(String... params) {
HttpURLConnection conn = null;
try {
URL url;
url = new URL(getHomeUrl() + "myPage.php");
conn = (HttpURLConnection) url.openConnection();
if( conn.getResponseCode() == HttpURLConnection.HTTP_OK ){
doThings(conn);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(conn != null) {
conn.disconnect();
}
}
return null;
}
如果 url 是http://www.mywebsite.com/myPage.php ,則連接正常。 But if the url is http://localhost/myPage.php or http://127.0.0.1:80/myPage.php with easyphp devserver on, I catch an IOException and get this:
有關信息,當我在瀏覽器中復制粘貼http://127.0.0.1:80/myPage.php時,授予訪問權限。
我讀到 android 模擬器可以“使用”本地主機,建議使用 10.0.2.2 代替,但它也不起作用。 我想這是 apache conf 的問題,但我有這個,這對我來說似乎是正確的:
<Directory "D:/Utilitaires/EasyPHP-Devserver-17/eds-www">
Options FollowSymLinks Indexes ExecCGI
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
任何想法?
您的服務器正在您的計算機上運行,因此127.0.0.1
僅在該計算機上運行。 如果您想通過手機訪問它,您應該寫下您計算機的本地地址(即: 192.168.10.100
)。 如果您的網絡配置正確,它將正常工作。
我建議您將您的網站上傳到公共主機,您可以輕松地從您的移動應用程序訪問它。
知道了 ! http://10.0.2.2失敗,但http://10.0.2.2:80 沒問題!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.