am trying to read web page from java code and its fine for general web site like google.com but when using the same code to read page on glassfish server at my computer i have this error:-
java.io.IOException: Server returned HTTP response code: 406 for URL: http://jedsms02:8080/Mirnint_Library-Mirnint_Message-context-root/Sending.jsp
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at java.net.URL.openStream(URL.java:1010)
at reader.ReadSMS.main(ReadSMS.java:195)
and this is my code:-
String urlString =
"http://localhost:8080/Mirnint_Library-Mirnint_Message-context-root/Sending.jsp"
try {
URL url;
url = new URL(urlString);
Scanner in = new Scanner(url.openStream());
while (in.hasNext())
System.out.println(in.nextLine());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I had change the URL by replace the localhost to IP "192.120.20.167" but i get this error
java.io.IOException: Server returned HTTP response code: 505 for URL: http://192.120.20.167:8080/Mirnint_Library-Mirnint_Message-context-root/Sending.jsp?Number=0xxxxxxxxx&Message= Test Man
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at java.net.URL.openStream(URL.java:1010)
at reader.ReadSMS.main(ReadSMS.java:195)
Please help, thank you
You are getting a 505 because your request parameters are not encoded. Use URLEncoder to encode your parameters, eg
URLEncoder.encode(" Test Man", "utf8");
The URL then becomes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.