使用Symfony API在Android上保存Http会话
我正在尝试向在Symfony中开发的API发送一些请求 我使用以下方式通过它进行连接:使用Symfony API在Android上保存Http会话,android,symfony,http,session,cookies,Android,Symfony,Http,Session,Cookies,我正在尝试向在Symfony中开发的API发送一些请求 我使用以下方式通过它进行连接: if (param.getRequestType().equals("post")) { HttpPost httppost = new HttpPost(url); try { httppost.setEntity(new UrlEncodedFormEntity(param.getParam()));
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;
}
它运行良好,API返回我已连接的状态
然后我想使用另一个API请求(get),但我的会话似乎没有保存,而且永远不会工作
get请求如下所示:
@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";
}
我认为这是因为Android不能让我的会话保持活跃。我说得对吗?我怎么能保留它
Symfony正在使用Fosuserbundle作为登录部分。我编辑了我的问题:我修改了get请求以使用CookieStore。但我仍然有完全相同的问题我编辑了我的问题:我修改了get请求以使用CookieStore。但我仍然有完全相同的问题