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

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 89314
          • 排名 - 647

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 中江县| 高密市| 诸城市| 林甸县| 惠安县| 社旗县| 平昌县| 桃源县| 博爱县| 长兴县| 青龙| 西和县| 义马市| 财经| 余姚市| 将乐县| 比如县| 江永县| 博客| 邵阳县| 河东区| 林口县| 石渠县| 巴林右旗| 太保市| 喀喇沁旗| 汝州市| 远安县| 吉木乃县| 朝阳区| 尚志市| 交口县| 武陟县| 辉南县| 浦城县| 睢宁县| 宁晋县| 城固县| 台山市| 五原县| 五台县|