public RestTemplate restTemplate(){ OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory(); RestTemplate restTemplate = new RestTemplate(factory );retrun restTemplate;}
ClientHttpRequestFactory requestFactory = new
HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
RestTemplate restTemplate = new RestTemplate(requestFactory);
发布评论
评论(5)
兄弟这个链接内容只是多了个header设置,我的参数都是英文,不存在乱码那些的。
兄弟,你确定 restTemplate post json是这么用的?
https://segmentfault.com/a/1190000007322338
不是这个的关系,我用过okhttp,就是底层用okhttp,也无法访问
public RestTemplate restTemplate(){ OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory(); RestTemplate restTemplate = new RestTemplate(factory );retrun restTemplate;}
问答我看还是上stackoverflow吧:
https://stackoverflow.com/questions/11178937/spring-resttemplate-gives-500-error-but-same-url-credentails-works-in-restcli
老外说要这样子初始化: