springboot RestTemplate请求

 

1.定义 RestTemplateConfig 配置类

@Configuration
public class RestTemplateConfig
{

  @Bean
  public RestTemplate restTemplate(ClientHttpRequestFactory factory)
  {
    return new RestTemplate(factory);
  }

  @Bean
  public ClientHttpRequestFactory simpleClientHttpRequestFactory()
  {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    factory.setReadTimeout(10000);//单位为ms
    factory.setConnectTimeout(10000);//单位为ms
    return factory;
  }
}

2.

@Autowired
private RestTemplate restTemplate;

3. 接口调用,数据解析
String url = zipKinUrl + "/zipkin/api/v1/traces?annotationQuery=&endTs="+currentTime
+"&limit=1000&lookback="+lookbackTime
+"&minDuration=&serviceName=twasp-gateway&sortOrder=duration-desc&spanName=all";

System.out.println("url = " + url);
//get json数据
JSONArray array = restTemplate.getForEntity(url, JSONArray.class).getBody();

 
上一篇:Ubuntu16.04安装NVIDIA驱动时的一些坑与解决方案


下一篇:android官方技术文档翻译——Android Lint