Как получить файлы cookie из POST-запроса?

Я могу отправлять POST-запросы с помощью org.apache.http.clien.HttpClientи получать HTTP-ответ. Но я не получаю HTML-контент при входе в систему, потому что для моего PHP-скрипта требуется файл cookie. Итак, как я могу прочитать файл cookie ответа на запрос POST и отправить его обратно с помощью запроса GET после запроса POST?

    HttpClient httpClient = new DefaultHttpClient();

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
    nameValuePairs.add(new BasicNameValuePair("username", "user"));  
    nameValuePairs.add(new BasicNameValuePair("password", "passwd"));  

    HttpPost httpPost = new HttpPost("http://localhost/index.php");
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    HttpResponse httpResponse = httpClient.execute(httpPost);

    BufferedInputStream bis = new BufferedInputStream(httpResponse.getEntity().getContent()); // Just gets the HTML content, not the cookies
5
задан Rox 28 April 2012 в 15:30
поделиться