0
正試圖從java代碼讀取網頁,並且它適用於一般網站如google.com,但是當使用相同的代碼在我的計算機上閱讀glassfish服務器上的頁面時,我擁有此錯誤: -使用java代碼在Glassfish服務器上請求網頁
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)
,這是我的代碼: -
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();
}
我不得不更換本地主機IP 「192.120.20.167」 更改URL,但我得到這個錯誤
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)
請大家幫忙, 謝謝
什麼,當你打開自己的網址,即把它放到瀏覽器地址欄發生了(先清除緩存,以確保你沒有得到一個不同由於緩存的結果)?服務器收到該請求後會說什麼? – Thomas 2011-12-29 09:42:08
其在瀏覽器中工作正常 – 2011-12-29 09:51:07
對不起,我發佈的錯誤是錯誤的這是錯誤堆棧 – 2011-12-29 09:52:51