我正在为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,并且还使用了Internet权限和usb调试。我只是想在设备上运行。是否有任何设置我必须在移动设备上更改或更改android项目,如在android清单文件或任何想法。
答案 0 :(得分:0)
模拟器可以正常工作,因为它与计算机位于同一网络上。如果要使用手机上的URL,则必须连接到服务器的网络。您使用的是本地 IP地址,因此您应该位于同一网络上。这将使用手机的无线连接。
您可以做的另一件事是使用外部 IP地址,这样您就不需要在同一个网络上。你应该谷歌的具体细节,但我认为你只需要找到你的外部 IP地址(whatismyip.com),并确保你要连接的端口在路由器的设置中打开(通常港口80)。这可以让你使用手机的3G或4G。
答案 1 :(得分:0)
我在node.js server
上也遇到了同样的问题
这是我解决此问题的方法:
Control Panel
System and Security
Windows Defender Firewall
下点击Allows app through windows firewall
Node.js server-side Javascript
并将其标记为正确