Spring HTTP POST请求

时间:2018-07-30 10:52:58

标签: spring rest http http-status-code-503

我一直在尝试向“ http://httpbin.org/post”发出POST请求,但无济于事。

    String apiUrl = "http://httpbin.org/post";
    RestTemplate restTemplate = new RestTemplate();

    String requestJson = "This is a test";
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    headers.add("Accept", "*/*");

    HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers);
    String answer = restTemplate.postForObject(apiUrl, entity, String.class);
    System.out.println("answer: " + answer);

页面(http://localhost:8080/greeting)上的错误提示...

  

发生意外错误(类型=内部服务器错误,   状态= 500)。

     

503服务不可用

我对Spring和REST还是很陌生,所以我可能对此有一个错误的理解。

感谢所有帮助!预先感谢!

如果有帮助...

  • 我一直在关注tutorial,并编辑其“ / greeting” 映射
  • 我正在使用IntelliJ IDEA社区2018.2

0 个答案:

没有答案