接口路径http1007189432600cuchulainnopenapiasset接口Basci Auth的Username是adminPassword是admin5java用restTemplate实现接口的调用然后返回接口打印到控制台
以下是Java代码示例:
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
public class AssetApiCaller {
private static final String BASE_URL = "http://100.71.8.94:32600/cuchulainn/openapi/asset";
private static final String USERNAME = "admin";
private static final String PASSWORD = "admin5";
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBasicAuth(USERNAME, PASSWORD);
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(BASE_URL, HttpMethod.GET, entity, String.class);
System.out.println("Response body: " + response.getBody());
}
}
这个示例使用了RestTemplate类来实现基于HTTP的远程调用。我们首先创建一个RestTemplate实例,然后设置HTTP请求的头部信息,其中包括Content-Type和Basic Auth的身份验证信息。接下来,我们创建一个HttpEntity对象,将头部信息作为参数传递,并指定HTTP方法为GET。最后,我们调用RestTemplate的exchange方法来发起HTTP请求,并将响应体打印到控制台
原文地址: https://www.cveoy.top/t/topic/gA2M 著作权归作者所有。请勿转载和采集!