有人能告诉我一个简单的例子,用json格式从android发布数据到asp mvc web服务器吗?我使用它来从asp.net mvc获取数据到json格式的android:
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);
并在asp.net中:
[HttpPost]
public ActionResult Api()
{
return Json(new { name = "test" });
}
它非常适合从asp.net mvc Web服务器获取数据,但是如何使用json格式或其他格式将数据从android发送到asp.net mvc控制器?