0

I'm trying to get a session cookies when i authenticate my user but i don't understand witch way is the best with Httpclient.

public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("id", "12345"));
    nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}}
togourt
  • 73
  • 1
  • 1
  • 4
  • Take a look at [this](http://stackoverflow.com/questions/4146861/android-httpclient-persistent-cookies) – Titus Apr 04 '15 at 18:13
  • yes, but this exemple is for put a cookie , not for get . I'm wrong ? – togourt Apr 04 '15 at 18:20
  • Is for creating a `HttpContext`, once you've set the context you can add as well as retrieve the cookies from it. – Titus Apr 04 '15 at 18:22

0 Answers0