whyclxw
2024-09-03 ca46c59e66ab37c12d4770f46aff8c631743f28c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.whyc.util;
 
import com.whyc.dto.ResultA200Dto;
import org.springframework.http.*;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
 
public class TestparamHttpUtil {
 
 
    //post请求传入form-data 格式
    public static Object postforform_data( RestTemplate restTemplate,String url,  MultiValueMap<String, Object> paramMap){
        HttpHeaders headers = new HttpHeaders();
        HttpMethod method = HttpMethod.POST;
        // 设置以表单的方式提交
        headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE);
        HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers);
        ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class );
        String results= response.getBody();
        Object dto= ActionUtil.getGson().fromJson(results, ResultA200Dto.class);
        return dto;
    }
}