android 发送json 到服务器

来源:互联网 发布:java怎么查询数据库 编辑:程序博客网 时间:2024/05/18 13:25
试试看发送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);
    }

原创粉丝点击