我在Android 4.1.2上遇到问题。我的aap在android 2. +和android 4.0上正确使用cookies但在android 4.1.2上我发送http post请求后无法从服务器获取cookie。我的代码:
public void auto()
{
EnterActivity.httpclient = new DefaultHttpClient();
EnterActivity.mHttpContext = new BasicHttpContext();
EnterActivity.mCookieStore = new BasicCookieStore();
EnterActivity.mHttpContext.setAttribute(ClientContext.COOKIE_STORE, mCookieStore);
HttpPost httpost = new HttpPost("http://.../oh.php");
System.out.println("LOLOLOLOLOOLOLO");
MultipartEntity entity = new MultipartEntity();
try
{
entity.addPart("login",new StringBody( getLastLogin() ));
entity.addPart("password", new StringBody( getLastPassword() ));
}
catch (UnsupportedEncodingException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
HttpResponse response = null;
try
{
response = EnterActivity.httpclient.execute(httpost, EnterActivity.mHttpContext);
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
dialogHandler.post(new DialogView( CONNECTION_ERRO ));
e.printStackTrace();
return ;
}
HttpEntity resEntity = response.getEntity();
if(mCookieStore.getCookies().size()>0)
System.out.println(" mCookieStore.getCookies().get(0).getValue(); =="
+ mCookieStore.getCookies().get(0).getValue());
else
System.out.println(" mCookieStore.getCookies().get(0).getValue(); == :(((");
...
}
答案 0 :(得分:0)
我编辑了我的时区,日期和时间。应用程序正常工作:)