http,post请求

第一种:
HttpRequest request = HttpUtil.createPost("http://dc-sync.tclking.com/proxy/jira/createIssue");
request.header("Content-Type", "multipart/form-data");
HashMap<String, Object> map = new HashMap<>();
map.put("username", "EX_SENLIN.KANG");
map.put("password","tmt#0923");
map.put("issueType","BUG");
map.put("summary","surfaceflinger V8-S48CT05-LF1V141 cpu在后台持续高 影响用户比例0.9130 平均占用16.36 最大占用20.50");
map.put("bugCategory","业务类bug");
map.put("components","测试问题1-模块");
map.put("projectIdOrKey","TN");
map.put("level","A");
map.put("description","");
map.put("assignee","EX_SENLIN.KANG");
map.put("epicLink","T972-1446");
map.put("labels","TMS发现问题;ANR");
map.put("versions","111");

request.form(map);
HttpResponse response = request.execute();
第二种:
MultiValueMap map2 = new LinkedMultiValueMap<>();
map2.setAll(map);
 RemoteResult remoteResult = ToolUtil.postIssuesMap(jiraUrl + IssuesConst.CreateIssueInterfacePath, map2, CreateIssueVo.class);
    public static <T> RemoteResult postIssuesMap(String url,  MultiValueMap params, Class<T> clazz){
    
    
        RestTemplate client = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        // 以表单的方式提交
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        //将请求头部和参数合成一个请求
        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
        //执行HTTP请求,将返回的结构使用ResultVO类格式化
        ResponseEntity<T> tResponseEntity = client.postForEntity(url, requestEntity, clazz);
        T body = tResponseEntity.getBody();

Guess you like

Origin blog.csdn.net/qq_44949002/article/details/121234713