gpt4 book ai didi

java - 尝试与 Web 服务通信时遇到 "No route to host"错误

转载 作者:太空狗 更新时间:2023-10-29 15:21:00 24 4
gpt4 key购买 nike

我正在尝试与笔记本电脑上的网络服务进行通信,并使用 Android 手机作为客户端。我试图做一个简单的登录功能,但是,每当客户端尝试与 web 服务通信时,这个错误就会在 Eclipse 上的 DDMS 中弹出。我可以通过家庭网络访问网络服务,但在学校时无法访问。如果您可能会问这个问题,我的 sch 中的 IP 地址是 172.22.XX.XX。虽然我知道是私有(private) IP 地址,但即使我的 Android 手机连接到同一网络,它仍然无法与笔记本电脑上运行的网络服务通信。谁能告诉我如何解决这个问题

10-20 15:00:42.875: 错误/AndroidRuntime(6728): fillInStackTrace():java.net.SocketException: 没有到主机的路由

这是完成工作的函数:

public String[] getPassword(String loginID){

String[] temp = null;
SoapObject request = new SoapObject(NAMESPACE, "GetPassword");

PropertyInfo quotesProperty = new PropertyInfo();
quotesProperty.setName("LoginID");
quotesProperty.setValue(loginID);
quotesProperty.setType(String.class);
request.addProperty(quotesProperty);

envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

String result = "";
HttpTransportSE httpRequest = new HttpTransportSE(URL);
httpRequest.debug = true;

try
{
httpRequest.call(SOAP_ACTION, envelope);
Log.e("Request",httpRequest.requestDump.toString());

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.e("Response",httpRequest.responseDump.toString());

result = response.toString();
if(result != null){
temp = result.split(";");
passwordSecurity crypto = new passwordSecurity();
temp[0]= crypto.cryptography(temp[0], false); //decrypt the password
}

}
catch(Exception e)
{
e.printStackTrace();
Log.e("AndroidRuntime", "getMessage(): "+e.getMessage());
Log.e("AndroidRuntime", "getLocalizedMessage(): "+e.getLocalizedMessage());
Log.e("AndroidRuntime", "fillInStackTrace(): "+e.fillInStackTrace().toString());

}
return temp;
}

来自 DDMS 的警告

10-20 16:56:32.180: WARN/System.err(13034): java.net.SocketException: No route to host
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
10-20 16:56:32.180: WARN/System.err(13034): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
10-20 16:56:32.180: WARN/System.err(13034): at java.net.Socket.connect(Socket.java:1002)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
10-20 16:56:32.180: WARN/System.err(13034): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
10-20 16:56:32.180: WARN/System.err(13034): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
10-20 16:56:32.180: WARN/System.err(13034): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
10-20 16:56:32.180: WARN/System.err(13034): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
10-20 16:56:32.180: WARN/System.err(13034): at android.wps.server.operations.WifiPositioningServices.getPassword(WifiPositioningServices.java:43)
10-20 16:56:32.180: WARN/System.err(13034): at android.wps.MainActivity$1.onClick(MainActivity.java:67)
10-20 16:56:32.180: WARN/System.err(13034): at android.view.View.performClick(View.java:2538)
10-20 16:56:32.180: WARN/System.err(13034): at android.view.View$PerformClick.run(View.java:9152)
10-20 16:56:32.180: WARN/System.err(13034): at android.os.Handler.handleCallback(Handler.java:587)
10-20 16:56:32.180: WARN/System.err(13034): at android.os.Handler.dispatchMessage(Handler.java:92)
10-20 16:56:32.180: WARN/System.err(13034): at android.os.Looper.loop(Looper.java:123)
10-20 16:56:32.180: WARN/System.err(13034): at android.app.ActivityThread.main(ActivityThread.java:3691)
10-20 16:56:32.180: WARN/System.err(13034): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 16:56:32.180: WARN/System.err(13034): at java.lang.reflect.Method.invoke(Method.java:507)
10-20 16:56:32.180: WARN/System.err(13034): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
10-20 16:56:32.180: WARN/System.err(13034): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
10-20 16:56:32.180: WARN/System.err(13034): at dalvik.system.NativeStart.main(Native Method)

最佳答案

From inside the Android emulator ,主机(您的笔记本电脑)是 10.0.2.2 - 无论主机的实际 IP 地址是什么,这应该始终有效。

关于java - 尝试与 Web 服务通信时遇到 "No route to host"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7832425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com