posts - 0,  comments - 5,  trackbacks - 0
          /*
          ?*?Created?on?2007-1-20
          ?*
          ?*?TODO?To?change?the?template?for?this?generated?file?go?to
          ?*?Window?-?Preferences?-?Java?-?Code?Style?-?Code?Templates
          ?
          */

          package ?test;

          import ?org.apache.commons.httpclient.HttpClient;
          import ?org.apache.commons.httpclient.HttpMethod;
          import ?org.apache.commons.httpclient.methods.GetMethod;
          import ?org.apache.commons.httpclient.methods.PostMethod;


          /**
          ?*?
          @author ?Administrator
          ?*
          ?*?TODO?To?change?the?template?for?this?generated?type?comment?go?to
          ?*?Window?-?Preferences?-?Java?-?Code?Style?-?Code?Templates
          ?
          */

          public ? class ?URLUtil {
          ????
          ????
          private ? static ?String?url? = ? "" ;
          ????
          private ? static ? final ?String?loginUrl? = ? "" ;
          ????
          private ? static ?HttpClient?client? = ? null ;
          ????
          private ? static ?PostMethod?method? = ? null ;
          ????
          ????
          public ? static ? void ?setUrl(String?url1) {
          ????????url?
          = ?url1;
          ????}

          ????
          ????
          public ? static ? void ?init() {
          ????????
          if (client? == ? null ) {
          ????????????
          try ? {
          ????????????????client?
          = ? new ?HttpClient();
          ????????????????method?
          = ? new ?PostMethod(loginUrl);
          ????????????????client.executeMethod(method);
          ????????????}
          ? catch ?(Exception?e)? {
          ????????????????System.out.println(
          " ----系統初始化失敗!---- " );
          ????????????????e.printStackTrace();
          ????????????}

          ????????}

          ????}

          ????
          ????
          public ? static ?String?getHtml() {
          ????????String?contentStr?
          = ? "" ;
          ????????init();
          ????????
          try {
          ????????????HttpMethod?postMethod?
          = ? new ?GetMethod(url);
          ????????????client.executeMethod(postMethod);
          ????????????contentStr?
          = ?postMethod.getResponseBodyAsString();
          ????????????postMethod.releaseConnection();
          ????????}
          catch (Exception?e) {
          ????????????release();
          ????????????getHtml();
          ????????}

          ????????
          return ?contentStr;
          ????}

          ????
          ????
          public ? static ? void ?release() {
          ????????
          if (method? != ? null )method.releaseConnection();
          ????????
          if (client? != ? null )client? = ? null ;
          ????}

          ????
          ????
          public ? static ? void ?main(String[]?args) {
          ????????URLUtil.setUrl(
          "" );
          ????????System.out.println(getHtml());
          ????}

          }

          posted on 2008-10-08 13:50 crazy 閱讀(642) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 三门县| 海南省| 闽清县| 墨玉县| 皋兰县| 丰城市| 越西县| 丰镇市| 峡江县| 犍为县| 荔波县| 蓝田县| 宜兰市| 安塞县| 固原市| 宝鸡市| 海原县| 德昌县| 宁远县| 临沧市| 栾川县| 缙云县| 融水| 衡南县| 磐安县| 镇坪县| 黎川县| 霍城县| 德保县| 温州市| 宣汉县| 锡林郭勒盟| 同江市| 郁南县| 卢龙县| 巴林右旗| 巢湖市| 衡东县| 海丰县| 威宁| 昌吉市|