将多个对象链接到 HttpEntity

Linking multiple objects to HttpEntity

我的其余部分 api 使用 POST 带有 2 个对象参数的请求:自定义类型和 long

我可以 link 像这样将一个参数传递给正文:

private void createCaseParticipant(long caseId, CaseParticipantDTO caseParticipantDTO)
    {
        HttpHeaders headers = new HttpHeaders();
        headers.add(AUTHORIZATION_HEADER_NAME, BASIC_AUTHORIZATION_HEADER_PREFIX + cmsRestApiCreds);

        HttpEntity<CaseParticipantDTO> postRequest = new HttpEntity<CaseParticipantDTO>(caseParticipantDTO, headers);
    }

如何向我的请求添加第二个参数? 谢谢

您可以像这样简单地将它添加到 HttpHeaders 对象中:

private void createCaseParticipant(long caseId, CaseParticipantDTO caseParticipantDTO)
    {
        HttpHeaders headers = new HttpHeaders();
        headers.add(AUTHORIZATION_HEADER_NAME, BASIC_AUTHORIZATION_HEADER_PREFIX + cmsRestApiCreds);
        headers.add("caseId",caseId.toString());
        headers.add("caseParticipantDTO", caseParticipantDTO.toString());
        HttpEntity<CaseParticipantDTO> postRequest = new HttpEntity<CaseParticipantDTO>(caseParticipantDTO, headers);
    }