RestTemplate 不适用于参数(URL、请求、Class<String>)

RestTemplate is not applicable for the arguments (URL, Request,Class<String>)

我无法 post 使用 RestTemplate 请求。它在

行显示以下错误
The method postForObject(URI, Object, Class<T>) in the type RestTemplate is 
not applicable for the arguments (URL, Request, 
 Class<String>)

代码

        URL url = new URL("http://testnl.etbxml.com/api");
        Authentication auth = new Authentication("Test", "test");
        auth.setFunction("SearchAvailability");

        Request req = new Request("test");
        req.setAuth(auth);
        req.setCityid(23);
        req.setStartdate("2015-11-20");
        req.setEnddate("2015-11-29");
        req.setRating(4);
        req.setNoofpersons(2);
        req.setLanguage("en");
        req.setCurrency("EUR");
        req.setCustomerIP(MY_IP);
        req.setAuth(auth);

        RestTemplate restTemplate = new RestTemplate();
        //restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
        //restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
        //String response = restTemplate.postForObject(url, req, EasyToBook.class);
        //Line 21
        Easytobook ea = restTemplate.postForObject(url, req, String.class);

        auth.setFunction("SearchAvailability");

您正在使用 URL instance but RestTemplate expects an object of type URI

只需替换这一行:

URL url = new URL("http://testnl.etbxml.com/api");

这一行:

URI url = new URI("http://testnl.etbxml.com/api");

这应该可以解决问题。