How to send post request with x-www-form-urlencoded body

前端 未结 2 1348
旧时难觅i
旧时难觅i 2020-11-29 03:01

\"Request

How in java, can I send a request with x-www-form-urlencoded header. I don\

2条回答
  •  迷失自我
    2020-11-29 03:19

    For HttpEntity, the below answer works

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    
    MultiValueMap map= new LinkedMultiValueMap();
    map.add("email", "first.last@example.com");
    
    HttpEntity> request = new HttpEntity>(map, headers);
    
    ResponseEntity response = restTemplate.postForEntity( url, request , String.class );
    

    For reference: How to POST form data with Spring RestTemplate?

提交回复
热议问题