我是Android应用程序开发的新手,我需要两个文本框用户名和密码,它将登录到服务器并使用php页面与数据库进行检查,如果登录成功,则转到下一个屏幕,否则显示一个msg框显示登录错误我该怎么办?
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://google.com");
EditText tw =(EditText) findViewById(R.id.EditText01);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int status = response.getStatusLine().getStatusCode();
tw.setText(status);
} catch (ClientProtocolException e) {
tw.setText(e.toString());
} catch (IOException e) {
tw.setText(e.toString());
}
}
回首忆惘然
相关分类