android 发送json 到服务器

来源:互联网 发布:3d地球仪软件 编辑:程序博客网 时间:2024/05/17 03:46

http://sizeed.blog.163.com/blog/static/9652545120111024917165/

试试看发送json到服务器上:
Reader r;
String url = "http://10.111.111.43:9000/XentivoCrm/services/VisitJSON";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(url);
InputStream data = null;
try {
     ObjectMapper mapper = new ObjectMapper();           
     mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    String json = mapper.writeValueAsString(mStringArray);
//I used jackson to create json, but built-in json.org will work
        StringEntity se = new StringEntity(json);
        httpost.setEntity(se);
        httpost.setHeader("json", "application/json");
        httpost.setHeader(HTTP.CONTENT_TYPE, "application/json");
        HttpResponse response = httpClient.execute(httpost);
    }