看完後: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