httpClient发送json的小程序 5C

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

1个回答

    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));
qq_23039605
小与哥 回复nanshangzhongdouren: 去这个网址 http://mvnrepository.com/ 下载 httpclient-4.5.2 & httpcore-4.4.4 这2个jar包
3 年多之前 回复
nanshangzhongdouren
金陵种豆人 要导的是什么包呢。你导的包不对啊
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问