posts - 66,  comments - 40,  trackbacks - 0

          package test;

          import java.io.IOException;

          import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
          import org.apache.commons.httpclient.HttpClient;
          import org.apache.commons.httpclient.HttpException;
          import org.apache.commons.httpclient.HttpStatus;
          import org.apache.commons.httpclient.methods.GetMethod;
          import org.apache.commons.httpclient.params.HttpMethodParams;
          import org.apache.commons.httpclient.protocol.Protocol;

          public class NoCertificationHttpsGetSample {
          ?public static void main(String[] args) {
          ??Protocol myhttps = new Protocol("https",
          ????new MySecureProtocolSocketFactory(), 443);
          ??Protocol.registerProtocol("https", myhttps);
          ??// 構造HttpClient的實例
          ??HttpClient httpClient = new HttpClient();
          ??// 創建GET方法的實例
          ??GetMethod getMethod = new GetMethod("??// 使用系統提供的默認的恢復策略
          ??getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
          ????new DefaultHttpMethodRetryHandler());
          ??try {
          ???// 執行getMethod
          ???int statusCode = httpClient.executeMethod(getMethod);
          ???if (statusCode != HttpStatus.SC_OK) {
          ????System.err.println("Method failed: "
          ??????+ getMethod.getStatusLine());
          ???}
          ???// 讀取內容
          ???byte[] responseBody = getMethod.getResponseBody();
          ???// 處理內容
          ???System.out.println(new String(responseBody));
          ??} catch (HttpException e) {
          ???System.out.println("Please check your provided http address!");
          ???// 發生致命的異常,可能是協議不對或者返回的內容有問題
          ???e.printStackTrace();
          ??} catch (IOException e) {
          ???// 發生網絡異常
          ???e.printStackTrace();
          ??} finally {
          ???// 釋放連接
          ???getMethod.releaseConnection();
          ??}

          ?}
          }


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2007年1月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          Welcome here, my friend!

          常用鏈接

          留言簿(12)

          隨筆檔案(66)

          文章分類

          文章檔案(63)

          web

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 89427
          • 排名 - 647

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 桓台县| 虞城县| 张掖市| 新晃| 石狮市| 宁河县| 西平县| 新巴尔虎右旗| 岱山县| 扶沟县| 筠连县| 左贡县| 高碑店市| 张北县| 房山区| 固阳县| 大石桥市| 呼和浩特市| 庆元县| 霍林郭勒市| 宣化县| 石景山区| 伊宁县| 习水县| 奉化市| 松江区| 洛南县| 海门市| 永平县| 河池市| 西城区| 蓬安县| 威宁| 安岳县| 富阳市| 浦北县| 社会| 鄂伦春自治旗| 辰溪县| 长武县| 博野县|