I am trying to send some requests to an API developed in Symfony.
I connect through it using this :
if (param.getRequestType().equals("post")) {
HttpPost httppost = new HttpPost(url);
try {
httppost.setEntity(new UrlEncodedFormEntity(param.getParam()));
HttpResponse res = httpclient.execute
(httppost);
return EntityUtils.toString(res.getEntity());
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
It works well and the API return that I am connected.
Then I want to use an other API request (get) but it seems that my session is not saved and it never works.
The get request looks like this :
@Override
protected String doInBackground(String... uri) {
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://***.**/***/faq");
String responseString = null;
try {
HttpResponse response = httpclient.execute(httpget, localContext);
StatusLine statusLine = response.getStatusLine();
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = out.toString();
System.out.println("HERE --> " + responseString);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return "error";
}
I think this is happening because Android doesn't keep my session alive. Am I right ? How can I keep it ?
Symfony is using Fosuserbundle for the login part.