2017-07-31 6 views
0

httppostを使ってログインしました。 DefaultHttpClientは推奨されていません。どうすればクッキーを入手できますか?廃止予定のDefaultHttpClientとcookieの代替ですか?

 request.setHeader("Content-Type", "application/json; charset=utf-8"); 
     request.setEntity(new StringEntity(obj.toString(), "utf-8")); 
     DefaultHttpClient client = new DefaultHttpClient(); 
     HttpResponse response = client.execute(request); 

と::

私は、このように前に使用

for (Cookie cookie : client.getCookieStore().getCookies()) { 
       if (cookie.getName().contains(".ASPXAUTH")) 
        return cookie; 
      } 

が、今、私は私がクッキーを得ることができる方法がわかりませんか?

私はあなたのアイデアが何であるか?THX

答えて

0

また、コード

String url = "http://www.google.com/search?q=mkyong"; 

     URL obj = new URL(url); 
     HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 

     // optional default is GET 
     con.setRequestMethod("GET"); 

     //add request header 
     con.setRequestProperty("User-Agent", USER_AGENT); 

     int responseCode = con.getResponseCode(); 
     System.out.println("\nSending 'GET' request to URL : " + url); 
     System.out.println("Response Code : " + responseCode); 

     BufferedReader in = new BufferedReader(
       new InputStreamReader(con.getInputStream())); 
     String inputLine; 
     StringBuffer response = new StringBuffer(); 

     while ((inputLine = in.readLine()) != null) { 
      response.append(inputLine); 
     } 
     in.close(); 

     //print result 
     System.out.println(response.toString()); 
の下のHttpURLConnectionチェックを使用することができます compile "cz.msebera.android:httpclient:4.4.1.2"

をbuild.gradleする新しいapacheのlibを追加しました

関連する問題