Spring MVC - Calling a rest service from inside another rest service

前端 未结 2 440
失恋的感觉
失恋的感觉 2021-02-06 14:48

I\'m currently having a really weird issue with calling one REST service from inside another one and I could really use a hand in working out what I\'m doing wrong.

相关标签:
2条回答
  • 2021-02-06 15:42

    A HTTP415 means Unsupported Media Type. What that means is that isUsernameAvailable expects input in JSON format, but that isn't what it is getting.

    Try explicitly adding Content-Type: application/json header to your HTTP request by doing the following:

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    
    HttpEntity<String> entity = new HttpEntity<String>(requestJson,headers);
    restTemplate.put(uRL, entity);
    
    0 讨论(0)
  • 2021-02-06 15:43

    Use RestTemplate.exchange mentioned below :

    ResponseEntity<String> response = RestTemplate.exchange(EndPointURL, HttpMethod.GET/POST/PUT/DELETE, HttpEntity/headers, URI-Variables)
    

    The input paramater's are described below :

    • EndpointURL -- SOAP End point URL ,that the REST service has to consume.

    • HTTPMethod -- Method Type such as GET ,PUT ,POST ,DELETE etc.

    • HTTPEntity -- Soap requires for mandatory sender headers.Make sure that you set your header(s) name and value as key-Value pair in HTTP headers.

    • URI-Variables -- (Object... urivariables) such as String.class ,Integer.class

      You should also put the connectTimeout , isSSLDisabled, responseCached in the constructor while generating request to restTemplate.

    0 讨论(0)
提交回复
热议问题