邮件标题字段中的非法字符:Content-Type:

时间:2018-11-08 14:29:45

标签: java spring-boot http-headers

跟随一个说我需要发送此POST请求的API:

    POST https://api.vasttrafik.se/token HTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    Authorization: Basic UmJseEkyeTFsWVNFTTZ0Z2J6anBTa2E0R1o6Wk1nSkR0Y0pddaRGV4OTJldUxpQUdYOFExUnU=
    grant_type=client_credentials&scope=<device_id>

我正在尝试在春季启动时构建相应的POST-req,这就是我想出的。但是我最终遇到标题中描述的错误。

    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type:", "application/x-www-form-urlencoded");


    headers.set("Authorization", "Basic UmJseEkyeTFsWVNFTTZ0Z2J6anBTa2E0R1o6Wk1nSkR0Y0paRGV4OTJldUxpQUdYOFExUnU=");

    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    ResponseEntity<String> respEntity = restTemplate.exchange("https://api.vasttrafik.se/token", HttpMethod.POST, entity, String.class);

    System.out.println(respEntity);

0 个答案:

没有答案