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

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 89692
          • 排名 - 647

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 濮阳县| 平顶山市| 吕梁市| 阳新县| 沁源县| 高碑店市| 甘孜| 宜阳县| 吉木萨尔县| 昆明市| 固镇县| 易门县| 莎车县| 进贤县| 织金县| 且末县| 清流县| 项城市| 绥江县| 石棉县| 宜都市| 大悟县| 邵武市| 民权县| 黄浦区| 通化县| 安平县| 札达县| 五河县| 合作市| 江门市| 平陆县| 东源县| 龙井市| 卓尼县| 开鲁县| 仁怀市| 凤山市| 永嘉县| 宁明县| 望都县|