2011-12-29 29 views
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) 

请大家帮忙, 谢谢

+0

什么,当你打开自己的网址,即把它放到浏览器地址栏发生了(先清除缓存,以确保你没有得到一个不同由于缓存的结果)?服务器收到该请求后会说什么? – Thomas 2011-12-29 09:42:08

+0

其在浏览器中工作正常 – 2011-12-29 09:51:07

+0

对不起,我发布的错误是错误的这是错误堆栈 – 2011-12-29 09:52:51

回答

相关问题