springboot java呼叫flask python寫的

木头左發表於2024-04-19

服務a用flask,服務b用的springboot,服務a寫的介面,用python很容易就調通了,java來調,坑有點多

1、url最後的斜槓必須兩邊對應上,否則flask會先308,而且 content type [text/html;charset=utf-8],連對應的HttpMessageConverter都沒有

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [com.api.ApiResponse<java.lang.String>] and content type [text/html;charset=utf-8]

2、get請求的引數傳遞,

兩種方式,一是uri引數

如/api/v1/test/{code}}
restTemplate.exchange(URL, HttpMethod.GET, new HttpEntity(), new ParameterizedTypeReference<ApiResponse<List>>() {
}, code);

另一種,接在uri上,如如/api/v1/test/?code=358

restTemplate.exchange(URL, HttpMethod.GET, new HttpEntity

相關文章