开发者

I have created a login page. How to send these login parameters over to the server for validation and get the result back?

EditText userName = (Ed开发者_Python百科itText) findViewById(R.id.EditText01);
EditText passWord = (EditText) findViewById(R.id.EditText02);
String user=userName.getEditableText().toString();
String pass=passWord.getEditableText().toString();

what to do after this?


Take a look at the HttpURLConnection class. The documentation describes the steps to connect to a server and receive a response. Be aware that network connections take time and you should not do this on the UI thread. You should start a worker thread to do the validation and put up some sort of "busy" notice on the UI thread. The article Painless Threading has lots of info about this.


I used the following code:

    URL url = new URL("http://www.my-site.com/auth_user.php?username="+username+"&pwd="+pwd);
    URLConnection authCustomerConn = url.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(authCustomerConn.getInputStream()));
    String inputLine;
    String res = "";
    if ((inputLine = in.readLine()) != null) 
        res += inputLine;
    in.close();        
    Integer success = Integer.valueOf(res);
    // check if succeed
    ...

And don't forget to implement auth_user.php on your server :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜