美文网首页
http post json

http post json

作者: 小明17 | 来源:发表于2020-05-05 16:10 被阅读0次

maven: httpclient,fastjson

    public static void sendPost(Object data) throws IOException {
        HttpClient client = HttpClientBuilder.create().build();
        HttpPost postRequest = new HttpPost("https://...");

        StringEntity input = new StringEntity(JSON.toJSONString(data));
        input.setContentType("application/json");
        postRequest.setEntity(input);
        HttpResponse response = client.execute(postRequest);

        if (response.getStatusLine().getStatusCode() != 200) {
            logger.error("Failed : HTTP error code : "
                    + response.getStatusLine().getStatusCode());
        } else {
            logger.info("send post request success!");
        }

    }

相关文章

网友评论

      本文标题:http post json

      本文链接:https://www.haomeiwen.com/subject/ftgmghtx.html