<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          HttpComponentsJava的HTTP協(xié)議庫

          聯(lián)合創(chuàng)作 · 2023-09-29 11:35

          HttpComponents 也就是以前的httpclient項目,可以用來提供高效的、最新的、功能豐富的支持 HTTP 協(xié)議的客戶端/服務器編程工具包,并且它支持 HTTP 協(xié)議最新的版本和建議。不過現(xiàn)在的 HttpComponents 包含多個子項目,有:

          • HttpComponents Core

          • HttpComponents Client
          • HttpComponents AsyncClient
          • Commons HttpClient

          以下列出的是 HttpClient 提供的主要的功能,要知道更多詳細的功能可以參見 HttpClient 的主頁。

          • 實現(xiàn)了所有 HTTP 的方法(GET,POST,PUT,HEAD 等)

          • 支持自動轉向

          • 支持 HTTPS 協(xié)議

          • 支持代理服務器等

          • 支持Cookie

          HttpClient 示例代碼:

          DefaultHttpClient httpclient = new DefaultHttpClient();
          try {
          	HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt");
          
          	HttpResponse response = httpclient.execute(httpget);
          	HttpEntity entity = response.getEntity();
          
          	System.out.println("Login form get: " + response.getStatusLine());
          	EntityUtils.consume(entity);
          
          	System.out.println("Initial set of cookies:");
          	List<Cookie> cookies = httpclient.getCookieStore().getCookies();
          	if (cookies.isEmpty()) {
          		System.out.println("None");
          	} else {
          		for (int i = 0; i < cookies.size(); i++) {
          			System.out.println("- " + cookies.get(i).toString());
          		}
          	}
          
          	HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" +
          			"org=self_registered_users&" +
          			"goto=/portal/dt&" +
          			"gotoOnFail=/portal/dt?error=true");
          
          	List <NameValuePair> nvps = new ArrayList <NameValuePair>();
          	nvps.add(new BasicNameValuePair("IDToken1", "username"));
          	nvps.add(new BasicNameValuePair("IDToken2", "password"));
          
          	httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
          
          	response = httpclient.execute(httpost);
          	entity = response.getEntity();
          
          	System.out.println("Login form get: " + response.getStatusLine());
          	EntityUtils.consume(entity);
          
          	System.out.println("Post logon cookies:");
          	cookies = httpclient.getCookieStore().getCookies();
          	if (cookies.isEmpty()) {
          		System.out.println("None");
          	} else {
          		for (int i = 0; i < cookies.size(); i++) {
          			System.out.println("- " + cookies.get(i).toString());
          		}
          	}
          
          } finally {
          	// When HttpClient instance is no longer needed,
          	// shut down the connection manager to ensure
          	// immediate deallocation of all system resources
          	httpclient.getConnectionManager().shutdown();
          }

           

          瀏覽 17
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  人妻少妇a | 亚洲最大在线 | 欧美日比视频在线观看 | 无码一区二区四区 | 狠狠亲狠狠操 |