1

我编写了一个应用程序,其中我通过模拟器使用系统的 IP 地址连接到本地主机,但现在我想通过 Android 设备连接到 LocalHost

问题是每当我尝试通过应用程序连接时遇到问题,简而言之:本地主机没有响应.....

我正在使用 Wifi 连接本地主机..请提供任何帮助....

代码:

 public void onClick(View v) {

                String url = "http://ipaddress/checkLogin.php";
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("strUser", txtUser.getText().toString()));
                params.add(new BasicNameValuePair("strPass", txtPass.getText().toString()));
                String resultServer  = getHttpPost(url,params);
                Log.d("Entire string::", " "+resultServer);
4

2 回答 2

2

不要使用Wifi通过Android设备连接,始终使用USB通过设备连接LocalHost或放置文件并使用在线服务器制作数据库......

您的代码没有任何问题:

 public void onClick(View v) {

            String url = "http://ipaddress/checkLogin.php";
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("strUser", txtUser.getText().toString()));
            params.add(new BasicNameValuePair("strPass", txtPass.getText().toString()));
            String resultServer  = getHttpPost(url,params);
            Log.d("Entire string::", " "+resultServer);
于 2013-04-15T06:33:00.583 回答
1

USB 不为移动设备提供网络。如果它已连接到您的 wifi,则点击路由器提供的笔记本电脑地址。如果它连接到您的移动网络,则首先找出您的路由器外部 IP 地址,然后将某个端口转发到该 10.0.2.2:portno,最后您将能够从您的设备上看到该服务器。

C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf

onlineoffline tag - don't remove
    Order Deny,Allow
    Allow from all // change it Allow
    Allow from 127.0.0.1
于 2013-04-15T11:59:31.560 回答