九阴真经


RestTemplate之form表单提交

<ul> <li>form表单工具类:</li> </ul> <pre><code>public static JSONObject postByForm(HashMap&lt;String, String&gt; hashMap, String url) { logger.info("postByForm: url:{} req:{}", url, hashMap.toString()); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap&lt;String, String&gt; params = new LinkedMultiValueMap(); Set&lt;Map.Entry&lt;String, String&gt;&gt; map = hashMap.entrySet(); for (Map.Entry&lt;String, String&gt; stringStringEntry : map) { params.add(stringStringEntry.getKey(), stringStringEntry.getValue()); } HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt; requestEntity = new HttpEntity(params, headers); ResponseEntity&lt;JSONObject&gt; response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, JSONObject.class); JSONObject body = response.getBody(); logger.info("postByForm: url:{} resq:{}", url, body); return body; }</code></pre>

页面列表

ITEM_HTML