我有一个java程序代码,它调用servlet并显示服务器的输出。
import java.io.*;
import java.net.*;
public class CallTripPlanner {
public static void main(String[] args) throws Exception {
URL url= new URL ("http://192.168.1.2/BusAgency/stopdetails");//#
//*URL url= new URL ("http://102.181.138.27/BusAgency/stopdetails");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("target=" + "getAllStopDetails");
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
/*String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}*/
String decodedString = in.readLine();
System.out.println(decodedString);
in.close();
}
}
在本地主机输出中: MAHA-GANAPATHI-STOP 19.177679 72.947481 PIPE-LINE-MULUND-2 19.184165 72.948511 S H-KELKAR 19.183577 72.948854 ERLA 19.108312 72.840407
[当我使用网络浏览器使用Html调用它时,预期和相同。]
在远程主机输出中: 通过提供静态IP而不是本地主机来运行相同的程序时。用程序中带*标记的行替换#etag标记的行。但它在输出后提供带有HTML标记的标题信息。
我无法追查缺陷在哪里。
提前感谢。