httpClient发送json的小程序

用spring的组件包HttpClient写一个关于发送json的小程序。

    CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost("http://localhost:8080/ydgos/other/updateLogistic.jspx");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();

        String json = "{\\'name\\':\\'tom\\'}";
        formparams.add(new BasicNameValuePair("json", json));

        org.apache.http.client.entity.UrlEncodedFormEntity uefEntity = new org.apache.http.client.entity.UrlEncodedFormEntity(
                formparams, "utf-8");

        httpPost.setEntity(uefEntity);

        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        System.out.println(EntityUtils.toString(entity));