java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)

解决方案 »

  1.   

    谢谢您的关注
    代码很长没办法全部贴出  大概是这样的:
    for (int j=0; j<200;j++){//循环进行下面操作   query = URLEncoder.encode(query, "UTF-8");
       //初始化地址
       URL url = new URL("http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=" +
        "AVX79EnV34FRE9h3PBuR.TLe5n0o8gIWn5kfbw5et_oJqeOGvy_lrHfhp0c0Y7UiNN2yNsI-&output=json" +
        "&format=html&results=10&country=cn" +
        "&query="+ query);
       URLConnection connection = url.openConnection();
          // 得到 JSON response
       String line;
       StringBuilder builder = new StringBuilder();
       BufferedReader reader = new BufferedReader(
         new InputStreamReader(connection.getInputStream()));
       
       while((line = reader.readLine()) != null) {
        builder.append(line);
       }   String response = builder.toString();
       //System.out.println(response);
       JSONObject json = new JSONObject(response);   //{
         //处理得到的结果(过滤 并存入数据库)
        ………………………………
         }
    }循环几次  就出现上面异常  我现在采用  隔段次数程序延时 才能避免异常出现  请问有好办法吗????
      

  2.   

    query = URLEncoder.encode(query, "UTF-8");query为何在循环里,值会变吗
      

  3.   

    你安没安装防火墙,
    曾经通过java.net.URL连接一个网站,端口是80,
    本地安装了norton的防火墙,把80端口从监听列表里去掉就可以了,你试试应该不是程序的问题,也可能是网络的关系.网络错误