2017-07-06 4 views
0

http://www.gc-zb.com/index/index.html」 が、私はこのように動作すると私はエラーを得た:URLの521:サーバーは、HTTPレスポンスコードを返しにjava.io.IOException:私はURLのデータをクロールする

public class InvitedBids { 

    public static void main(String[] args) throws IOException { 

     InputStream inputStream=null; 
     HttpURLConnection httpConn=null; 
     InputStreamReader inputStreamReader=null; 
     BufferedReader bufferedReader=null; 
     StringBuilder contentBuf=null; 
     String myURL="http://www.gc-zb.com/index/index.html"; 
     URL url= null; 
     try { 
      url = new URL(myURL); 
      System.out.println(url); 
      httpConn= (HttpURLConnection) url.openConnection(); 
      httpConn.setRequestMethod("GET"); 

      inputStream=httpConn.getInputStream(); //error occurs 
      inputStreamReader=new InputStreamReader(inputStream,"utf-8"); 
      bufferedReader=new BufferedReader(inputStreamReader); 
      String line=""; 
      contentBuf=new StringBuilder(); 
      while ((line = bufferedReader.readLine())!= null) { 
       contentBuf.append(line); 
      } 
      String buf=contentBuf.toString(); 
      System.out.println(buf); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     }finally { 
      //close I/O and HTTP 
     } 

    } 
} 

コンソールは言う:

http://www.gc-zb.com/index/index.html 
java.io.IOException: Server returned HTTP response code: 521 for URL: http://www.gc-zb.com/index/index.html 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
    at com.feilong.bid.InvitedBids.main(InvitedBids.java:43) 

それを解決する方法を知っている人。ありがとう!

+0

521 Webサーバーがダウン 起源であるという問題を解決するにはサーバーがCloudflareからの接続を拒否しました。 https://en.wikipedia.org/wiki/List_of_HTTP_status_codesを参照してください。 – Luftbaum

答えて

0

Jonが先に述べたように、エラー521は、サーバーがダウンしていることを意味します。サーバーが起動するまで心配しないでください。 cloudflare docs

btw文書をクロールする場合は、JSOUPを使用してデータを取得することを強くお勧めします。私たちはそれを私の会社とrulzで使っています。

例:

Document doc = Jsoup.connect("http://example.com/").get(); 
String title = doc.title(); 

ドキュメント: https://jsoup.org/cookbook/input/load-document-from-url

0

推奨使用 org.apache.commons.httpclient.HttpClient

関連する問題