首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

http长连接错误处理情况

2012-12-18 
http长连接异常处理情况try {URL a new URL(args[0])URLConnection urlc a.openConnection()is co

http长连接异常处理情况
try {
    URL a = new URL(args[0]);
   URLConnection urlc = a.openConnection();
   is = conn.getInputStream();
    int ret = 0;
   while ((ret = is.read(buf)) > 0) {
      processBuf(buf);
    }
    // close the inputstream
    is.close();
} catch (IOException e) {
   try {
        respCode = ((HttpURLConnection)conn).getResponseCode();
       es = ((HttpURLConnection)conn).getErrorStream();
       int ret = 0;
        // read the response body
        while ((ret = es.read(buf)) > 0) {
            processBuf(buf);
       }
       // close the errorstream
        es.close();
    } catch(IOException ex) {
       // deal with the exception
   }
}

热点排行