我試圖用post方法登錄網站...我如何檢查我是否登錄了?如何檢查發佈方法,如果在android中登陸?
public void postData() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://svuonline.org/isis/index.php");
try {if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("user_name", user.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("user_pass",password.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) { }
catch (IOException e) { }
catch (Exception e) { }
}
此外,請查看[異步Http客戶端](http://loopj.com/android-async-http/)。我們一直在生產中使用它,並且效果非常好! – FMontano