### Question:
HttpUtil { public static String post(String requestUrl, Object data, ContentType contentType) { if (StringUtils.isBlank(requestUrl)) { throw new RuntimeException("requestUrl cann't be null"); } if (contentType == null) { throw new RuntimeException("contentType cann't be null"); } HttpPost post = new HttpPost(requestUrl); if (data != null) { StringEntity entity = new StringEntity(data.toString(), contentType); post.setEntity(entity); } logger.info("HttpClient request uri -> " + requestUrl); logger.info("HttpClient request body -> " + data); return executeRequest(post, contentType.getCharset()); }  static String get(String requestUrl); static String post(String requestUrl, Object data, ContentType contentType); static String uploadFile(String requestUrl, Object data);  }### Answer:
@Test public void postFormData() throws UnsupportedEncodingException { UpdateUserRequest request = new UpdateUserRequest("/user/updateUser"); request.setMethod(MethodTypeEnum.POST); request.setHttpContentType(ContentType.APPLICATION_FORM_URLENCODED); request.setUserId(1L); request.setUsername("李太白"); String result = HttpUtil.post(request.composeUrl(baseUrl, request.getQueryParameters()), null, request.getHttpContentType()); AbstractResponse response = JacksonUtil.readValue(result, request.getResponseClass()); log.info(response.toString()); }
@Test public void postJsonObject() throws UnsupportedEncodingException { CreateUserRequest request = new CreateUserRequest("/user/createUser"); request.setMethod(MethodTypeEnum.POST); request.setHttpContentType(ContentType.APPLICATION_JSON); CreateUserRequest.CreateUserBody body = new CreateUserRequest.CreateUserBody(); body.setUsername("白居易"); request.setBody(body); String result = HttpUtil.post(request.composeUrl(baseUrl, request.getQueryParameters()), JacksonUtil.toJson(request.getBody()), request.getHttpContentType()); AbstractResponse response = JacksonUtil.readValue(result, request.getResponseClass()); log.info(response.toString()); }