6

Can anyone show me an simple example about posting data with json format from android to asp mvc web server ? i used this for getting data from asp.net mvc to android with json format:

new Thread() {

                public void run() {
                    try{

                         JsonNode userData = null;
                         ObjectMapper mapper = new ObjectMapper();
                        HttpResponse res;
                        DefaultHttpClient httpclient = new DefaultHttpClient();
                        HttpPost post = new HttpPost(URI.create("http://mylink.com/test/api"));
                        res = httpclient.execute(post);
                        userData = mapper.readValue(res.getEntity().getContent(), JsonNode.class);
                        name= (String)userData.get("name").getTextValue();

                    }catch(Exception e){
                       Log.e("activity","dead",e);


                    }
                }
            }.start();
            editStatus.setText(name);

and in asp.net :

[HttpPost]
public ActionResult Api()
{

    return Json(new { name = "test" });
}

It's work perfectly for getting data from an asp.net mvc web server but how can i send data from android to asp.net mvc controller with json format or another format?

paradise_human
  • 922
  • 2
  • 12
  • 30
  • do you have to send data as json? if you're posting to mvc, you can simply post a form. would that suffice? – Dave Alperovich Aug 12 '13 at 13:34
  • I used jackson.lib and don't know how to modify java code to send an object or any data to mvc and I don't know the type of parameter that this section " public ActionResult Api()" is received ... no i dont have to send data as json... Lists also is a good choice .. – paradise_human Aug 12 '13 at 14:37
  • 3
    try this http://stackoverflow.com/questions/6218143/android-post-json-using-http – Dave Alperovich Aug 12 '13 at 15:01
  • thanks Dave A ... my problem is solved with your help ... – paradise_human Aug 12 '13 at 15:45

0 Answers0