0

I have an android application that uses a login page to access some statistics data. Yet the username and password is hard coded in the application. I want to link this app with an erlang server which will take user name and password for authentication and it takes JSON requests. I am a beginner and I want to know how to sent my username and password to the server url (172.16.11.70:81/prime/yaws/login.yaws) for authentication and recive the server response. suucess or failed. Step by step. Thank you.

4

1 に答える 1

0

アップデート

ユーザー名とパスワードを一致させるための次のコードがあります。上記の「応答」は次のようになります -> {"state":"bla bla blaa","re​​ason":"bla bla blaa"}

HttpClient client = new DefaultHttpClient();
                HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
                HttpResponse response;
                JSONObject json = new JSONObject();
                try{
                    HttpPost post = new HttpPost(URL);
                    post.setHeader("Content-type", "application/json");
                    json.put("username", userName);
                    json.put("password", password);
                    StringEntity se = new StringEntity( json.toString());  
                    Log.v("json_text", json.toString());
                    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                    post.setEntity(se);
                    response = client.execute(post);
                    /*Checking response */
                    if(response!=null){
                        String temp = EntityUtils.toString(response.getEntity()); //Get the data in the entity
                        Log.v("response", temp);
                }}
                catch(Exception e){
                    e.printStackTrace();
                    //createDialog("Error", "Cannot Estabilish Connection");
                }

この「レスポンス」をJava配列に変換したい。ヒントをください。

于 2012-09-20T08:35:23.213 に答える