1

I am Connecting to .NET web-service in android.and For login I used the code

Login method:

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();
}                            

and class that posts the Contents is:

  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 "";



}

And the response is :

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

The Problem is that I don't know how to get the Result,id,Username and password From this Format. Please Help To do this...

Thanks...

  • 3
    Have a look at JSON parsing. The string inside the XML is of JSONObject format. Weird thing is, it's bad practice to put JSON inside XML, since both formatting styles have kind of the same goal... So if you can change that, you should. Otherwise cry ever day about it! – Smokez May 05 '14 at 07:51
  • Did you write the web service? If so get rid of the XML encapsulation. – Squonk May 05 '14 at 07:53
  • http://www.shereef.net/2012/04/03/creating-a-wcf-web-service-that-returns-json-and-xml-format/ maybe helpful i wrote this ages ago but give it a look. – Shereef Marzouk May 05 '14 at 09:30
  • @Smokez, very right but i am kind of facing this problem as well – Pankaj Nimgade Apr 07 '15 at 04:56

0 Answers0