Java报错streamed,报错java.net.SocketException: Software caused

写道

在利用google搜索抓取结果页面的时候总抛出异常:

java.net.SocketException: Software caused connection abort: recv failed

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.read(SocketInputStream.java:147)

at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)

at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)

at java.io.BufferedInputStream.read(BufferedInputStream.java:317)

at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:697)

at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:640)

at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:662)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)

at AttrExtractor.search(AttrExtractor.java:96)

at AttrExtractor.main(AttrExtractor.java:56)

错误的地方说是在BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream()));

我是个菜鸟,不知道为什么报错,有没有大牛可以详细告诉我怎么办?!!!

url = new URL("http://www.google.com.hk/search?hl=en&q="+ss+"&ie=utf-8&oe=utf-8&start=0");

HttpURLConnection connection=(HttpURLConnection) url.openConnection();

connection.setConnectTimeout(12000);

connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");

connection.setRequestProperty("Accept", " images/gif, image/x-xbitmap, image/jpeg ,*/*");

connection.setRequestProperty("Accept-Encoding", "deflate");

connection.setRequestProperty("Accept-Charset", "null");

connection.setRequestProperty("Connection", "Keep-Alive");

connection.setDoInput(true);

connection.setInstanceFollowRedirects(false); ///防止Server redirected too many times

connection.setRequestMethod("GET");

connection.connect();

BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream()));

String line=null;

String s = "";

StringBuffer sb = new StringBuffer("");

//读取页面内容

while ((s = reader.readLine()) != null) {

sb.append(s+"\r\n");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值