我正在开发一个小型应用程序,并且需要进行身份验证。我正在尝试通过 php 连接到 MYsql db 来进行开发。
添加 uname/pw --> 日志记录 --> 发送到 php --> 检查 db --> ok 发送回 android --> 已验证。/ 错误发送回重新登录。
到目前为止,我已经发展了,我认为应该是这样,但我不确定,因为我对绳索真的很陌生。
请善意地帮助我进行接线。谢谢你。
public class Loging extends Activity{
TextView txt;
EditText uname,pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.loging);
Button b = (Button)findViewById(R.id.log);
uname = (EditText)findViewById(R.id.uname);
pwd = (EditText)findViewById(R.id.pwd);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", uname.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Pass", pwd.getText().toString()));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.helloworld.com/report.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
}
catch(Exception e)
{
Log.e("log_tag","Error in http connection"+e.toString());
}
}
});
}
}