java RestTemplate、Sping Boot 、POST

dxpyg8gm  于 5个月前  发布在  Java
关注(0)|答案(3)|浏览(44)

我在localhost:8086/addMessage上有一个rest API,当我使用POSTMAN测试它时,它可以工作。但是当我想在客户端集成这个API时,它返回:

java.net.URISyntaxException: Expected scheme-specific part at index 10: localhost:
    at java.net.URI$Parser.fail(URI.java:2848) ~[na:1.8.0_171]  error:

字符串
这是我调用API的方法:

public void addOrder(Message orders) throws  Exception
    {  RestTemplate restTemplate = new RestTemplate();
      String resp = restTemplate.postForObject(
                "localhost:8086/addMessage",
                orders,
                String.class);    
    }


我该怎么解决呢?

zqry0prt

zqry0prt2#

如果你使用localhost然后通过这样的url-http://localhost:8080/api/notes定义方案是重要的(http/https)不要使用空间也.对于你的问题答案应该是-http://localhost:8086/addMessage

vnjpjtjt

vnjpjtjt3#

添加**http://https://**方案的URL已为我工作

restTemplate.postForObject("http://localhost:8086/addMessage", orders, String.class);

字符串

restTemplate.postForObject("https://localhost:8086/addMessage", orders, String.class);


感谢@stacker和@Shubham

相关问题