gpt4 book ai didi

Android: 无法通过 Android 应用程序访问 Tomcat 服务器

转载 作者:行者123 更新时间:2023-11-28 23:59:12 26 4
gpt4 key购买 nike

我无法通过我的应用程序访问 Tomcat 服务器,但我可以在我的移动浏览器中打开相同的 URL。我的笔记本电脑和手机都连接到同一个路由器。也可以通过应用程序访问被评论的 url。

网络服务:

@Path("/hello")
public class FirstTest {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}

// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}

// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}

}

主要 Activity .java:

hit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new JSONClass().execute("http://192.168.0.100:8081/TrekServerTest2/rest/hello");
//new JSONClass().execute("https://jsonparsingdemo-cec5b.firebaseapp.com/jsonData/moviesDemoItem.txt");
}
});
}


public class JSONClass extends AsyncTask<String, String, String>{

@Override
protected String doInBackground(String... params) {
HttpURLConnection httpURLConnection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);

httpURLConnection = (HttpURLConnection) url.openConnection();

httpURLConnection.connect();

InputStream stream = httpURLConnection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line="";
while((line=reader.readLine())!=null){
buffer.append(line);
}
return buffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
return "wrongUrl";
} catch (IOException e) {
e.printStackTrace();
return "connError";
}
finally {
if(httpURLConnection!=null)
httpURLConnection.disconnect();
try {
if(reader!=null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
return "closeError";
}
}

}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
tv.setText(s);

}
}

日志:

     02-04 17:44:25.922 724-967/? E/WifiConfigStore: updateSavedNetworkHistory():  try "Logon broadband GP"WPA_PSK SSID="Logon broadband GP" Logon broadband GP [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] ajst=0
02-04 17:44:25.922 724-967/? E/WifiConfigStore: got known scan result 0c:d2:b5:51:82:c6 key : "Logon broadband GP"WPA_PSK num: 1 rssi=-65 freq=2417
02-04 17:44:25.942 724-967/? E/WifiAutoJoinController: status: bssid=0c:d2:b5:51:82:c6
freq=2417
ssid=Logon broadband GP
id=9
mode=station
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.0.104
p2p_device_address=02:0e:41:4c:1d:2b
address=00:0e:41:4c:1d:2b
uuid=c753c5e7-fbf6-58ae-b610-23d41c19c3e4
02-04 17:44:25.948 724-967/? E/WifiAutoJoinController: attemptAutoJoin() num recent config 1 current="Logon broadband GP"WPA_PSK ---> suppNetId=9
02-04 17:44:25.948 724-967/? E/WifiAutoJoinController: Done attemptAutoJoin status=0
02-04 17:44:25.951 724-967/? E/WifiConfigStore: writeKnownNetworkHistory() num networks:15 needWrite=false
02-04 17:44:26.059 724-967/? E/WifiStateMachine: ConnectedState (when=-2ms what=131155 arg1=29!CMD_RSSI_POLL 29 0 "Logon broadband GP" 0c:d2:b5:51:82:c6 rssi=-64 f=2417 sc=60 link=135 tx=0.0, 0.0, 0.0 rx=0.3 bcn=0 [on:0 tx:0 rx:0 period:1378] from screen [on:0 period:151781643] gl hn u24 rssi=-59 ag=0 hr ticks 0,0,399 ls-=0 [56,56,56,56,61] brc=0 lrc=0

最佳答案

我想我发现了我的案例中的错误所在。看起来我一直在使用错误的 IP 地址。我通过 ipconfig 获得的 ip 不是笔记本电脑和我的设备所连接的普通路由器。我尝试使用已连接 wifi 的属性中的 ip,瞧!..它起作用了。谢谢大家的努力。

关于Android: 无法通过 Android 应用程序访问 Tomcat 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039804/

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