2012-01-29 19 views
6

tanımlama bilgilerini kullanma ve yanıtı gösterme örneklerini kullanıyorum Bir java web uygulamasında apache http istemcisi (v4) ile çalışıyorum ve aşağıdaki durumlarda takılıyorum: basit kullanımJava-apache http istemci kullanım örnekleri, HTTPResponse nesnesinden

examples--

(1) kurabiye

kullanımına yönelik mevcut Apache HTTP istemcisi, farklı seçenekler ile çerezler nasıl kullanılır

(2) ayıklanıyor charset, mimetype, yanıt (KeyValuePair gibi) başlıkları ve budy (aynı yanıt, HTTPResponse nesnesinde mevcut olduğunda bayt []).

cevap

6

1) çerezler için AS, yani exapmle bkz: örnekler \

HttpComponents-client-4.1.3 \ org \ apache \ http örnekler \ istemci \ ClientCustomContext.java

ana kod \:

HttpEntity entity = response.getEntity(); 
entity.getContent() 

Sadece örnekleri okuyun: Eğer yanıtından gereken tüm ve alabilirsiniz

HttpClient httpclient = new DefaultHttpClient(); 
     try { 
      // Create a local instance of cookie store 
      CookieStore cookieStore = new BasicCookieStore(); 

      // Create local HTTP context 
      HttpContext localContext = new BasicHttpContext(); 
      // Bind custom cookie store to the local context 
      localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); 

      HttpGet httpget = new HttpGet("http://www.google.com/"); 

      System.out.println("executing request " + httpget.getURI()); 

      // Pass local context as a parameter 
      HttpResponse response = httpclient.execute(httpget, localContext); 
     } finally { 
      // When HttpClient instance is no longer needed, 
      // shut down the connection manager to ensure 
      // immediate deallocation of all system resources 
      httpclient.getConnectionManager().shutdown(); 
     } 

2): httpcomponents-client-4.1.3 \ example \ org \ apache \ http \ samples \ client httpcomponents-client-4.1.3-bin.zip dosyasının website numaralı sürümünden indirilir.