看完后:Getting the 'external' IP address in Java如何获得外部IP成功
代码:
public static void main(String[] args) throws IOException
{
URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String ip = in.readLine(); //you get the IP as a String
System.out.println(ip);
}
我认为我是一个胜利者,但我得到以下错误
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: http://automation.whatismyip.com/n09230945.asp
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at getIP.main(getIP.java:12)
我想这是因为服务器没有足够快速响应,是否有确保它会获得外部IP?
编辑:好了,所以它的被拒,其他网站可以做同样的功能
为HTTP 403错误代码意味着禁止。然而,我可以在我的浏览器中访问该网站,而不会有任何问题。 – twain249 2012-04-25 19:35:49