我知道的是我在做它錯誤;我不知道怎麼做纔對。 以下是Apache servlet的一些代碼。從Apache到Android應用程序的Cookie
@覆蓋
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/Cookie");// May be wrong
Cookie c = new Cookie("cookie", "CookieS i LOVE");
c.setMaxAge(60*60);response.addCookie(c);
}
For Android app i have this code to get the cookie sent from the that servlet.
Now i want to store that cookie on my android device. and then retrieve it for
another activities.
{....}
public void onClick(View v) {
HttpClient client = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://********:8080/***/servlet");
Cookie c = (Cookie) CookiePolicy.ACCEPT_ALL;
try {
HttpResponse execute = client.execute(httpget);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
List<Cookie> cookies = ((AbstractHttpClient)client).getCookieStore()
.getCookies();
String mycookie = cookies.toString();
Toast.makeText(Cookies.this, mycookie, Toast.LENGTH_SHORT).show();
}
}
}
Thank You for your help.
'然後檢索另一個activities'意味着同一個應用程序,但不同的活動或不同applicaitons? –
是的,它是登錄,所以第一個屏幕是註冊的東西,其餘的屏幕是出於商業目的。 –