我可以使用以下代码通过我的 android 应用程序登录到http://yearbook08.com/ :
String URL="http://yearbook08.com/login.php";
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = null;
HttpPost httppost = new HttpPost(URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userId", uname));
nameValuePairs.add(new BasicNameValuePair("password", pass));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
现在,当我移动到另一个活动时,我想检索http://yearbook08.com/wall.php但网络服务器无法识别我的上次登录并要求我再次登录。
有没有一种方法可以让我在登录后保持登录状态?请帮忙!