2

我正在为android制作客户端服务器应用程序,其中客户端是android,服务器是本地服务器。它在模拟器上成功运行,但不在设备上。它实际上并没有崩溃,而是从服务器给出响应

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
    <title>ERROR: The requested URL could not be retrieved</title>
</head>
<body>
    <div id="content">

    <h1>ERROR</h1>
    <h2>The requested URL could not be retrieved</h2>
    <hr/>
    <P>
     While trying to retrieve the URL:
    <A HREF="http://10.0.2.2/test/testing.php">http://10.0.2.2/test/testing.php</A>
    <P>
     The following error was encountered:
   <UL>
       <LI>
            <STRONG>
         Connection to 10.0.2.2 Failed
         </STRONG>
     </UL>
         <P>
     The system returned:
     <PRE><I>    (110) Connection timed out</I></PRE>
         <P>
         The remote host or network may be down.  Please try the request again.
            <P>Your cache administrator is <A HREF="mailto:webmaster">webmaster</A>. 
     </div>
           <!--
          -- Unfortunately, Microsoft has added a clever new
          -- feature to Internet Explorer.  If the text in
           -- an errors message is too small, specifically
           -- less than 512 bytes, Internet Explorer returns
           -- its own error message.  Yes, you can turn that
           -- off, but *surprise* its pretty tricky to find
          -- buried as a switch called smart error
           -- messages  That means, of course, that many of
           -- Resins error messages are censored by default.
           -- And, of course, youll be shocked to learn that
           -- IIS always returns error messages that are long
           -- enough to make Internet Explorer happy.  The
           -- workaround is pretty simple: pad the error
           -- message with a big comment to push it over the
           -- five hundred and twelve byte minimum.  Of course,
           -- thats exactly what youre reading right now.
         //-->
         </body></html>

我正在使用 httpclient 和 url 是 10.0.2.2 并且还使用互联网权限和 USB 调试。我只想在设备上运行。有没有我必须在移动设备上更改的设置或在 android 清单文件中更改 android 项目或任何想法。

4

2 回答 2

0

模拟器可以工作,因为它与计算机位于同一网络上。如果要在手机上使用 URL,则必须连接到服务器的网络。您使用的是本地IP 地址,因此您应该在同一个网络上。这将使用您手机的无线连接。

您可以做的另一件事是使用您的外部IP 地址,这样您就不需要在同一个网络上。你应该用谷歌搜索细节,但我认为你只需要找到你的外部IP 地址(whatismyip.com)并确保你要连接的端口在路由器的设置中是打开的(通常是端口 80)。这将让您使用手机的 3G 或 4G。

于 2013-03-22T13:58:55.873 回答
0

我也面临同样的问题node.js server

这是我如何解决这个问题的:

  1. Control Panel在你的电脑上 打开
  2. 点击System and Security 截屏
  3. Windows Defender Firewall点击 下方Allows app through windows firewall 截屏
  4. 找到Node.js server-side Javascript并标记正确 截屏
于 2018-07-02T18:41:53.807 回答