1

我正在连接到 android 中的 .NET 网络服务。为了登录,我使用了代码

登录方式:

public void logingin(View vvvv){
    if(Utils.CheckNet(contect)) {
 cv=new ContentValues();
cv.put("process", "login");
 cv.put("username", uname);
cv.put("password",pass);
flage = true;
showConnectingProgreesDialog(contect,true,"Connecting to server");
new Thread(){
public void run(){
response=Utils.postDataToServer("api_lgn",  cv);
mHandler.post(showDimage);
}
}.start();
 } else {
 Toast.makeText(contect, "Requires Network Connectivity", Toast.LENGTH_LONG).show();
}                            

发布内容的类是:

  public static String postDataToServer(String pagename,
                ContentValues postcontents) {
            try {
                String u = weburl + pagename;
                Log.i("url", u);
                org.apache.http.client.HttpClient cl = new DefaultHttpClient();
                org.apache.http.client.methods.HttpPost req = new org.apache.http.client.methods.HttpPost(
                        u);
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                        postcontents.size());
                Set<Entry<String, Object>> t = postcontents.valueSet();
                for (Entry<String, Object> entry : t) {

                    nameValuePairs.add(new BasicNameValuePair(entry.getKey()
                            .toString(), entry.getValue().toString()));
                }
                req.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse resp = cl.execute(req);
                Log.i("http post request`", req.getURI().getPath().toString());
                BufferedReader reader = new BufferedReader(new InputStreamReader(resp
                        .getEntity().getContent()));
                if (reader != null) {
                     StringBuilder sb=new StringBuilder();

                     String line=null;
                     while((line=reader.readLine())!=null){
                         sb.append(line);
                     }
                    Log.d("post_response", sb.toString());
                    return sb.toString();
                }
                Log.d("post_response null", reader.readLine()+" ");
            } catch (Exception e) {
                Log.d("@utils.unamepswd", e.toString());

            }
            return "";



}

回应是:

<?xml version="1.0" encoding="utf-8"?><string xmlns="http://tempuri.org/ { Result : Success , Id : 1 , UserName : Myname , Password :null} /string>

问题是我不知道如何从此格式获取结果、id、用户名和密码。请帮助执行此操作...

谢谢...

4

0 回答 0