package com.ycl.api.HK; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import java.net.URI; @Slf4j public class HKApi { public static void test() { DefaultHttpClient httpclient = new DefaultHttpClient(); String hostUrl = "http://51.95.68.80"; // 获取焦距 String url = hostUrl + "/ISAPI/System/Video/inputs/channels/1/overlays"; URI serverURI = null; try { serverURI = new URI(url); HttpGet httpGet = new HttpGet(url); String username = "admin"; String password = "zg@2024dx"; Credentials creds = new UsernamePasswordCredentials(username, password); httpclient.getCredentialsProvider(). setCredentials( new AuthScope(serverURI.getHost(), serverURI. getPort()), (Credentials) creds); HttpResponse response = httpclient.execute(httpGet); String resultString = EntityUtils.toString(response.getEntity(), "utf-8"); log.info(resultString); } catch (Exception e) { e.printStackTrace(); } } }