import org.kuali.khc.http.*; import java.net.URI; public class HttpClientExample { public static void main(String[] args) { try { HttpConnection connection = HttpConnection.newBuilder() .setUri(new URI("https://example.com/api")) .setMethod(HttpMethod.POST) .setBody("{\"param1\":\"value1\"}") .build(); HttpResponse response = connection.execute(); System.out.println("Response Code: " + response.getResponseCode()); System.out.println("Response Body: " + response.getBody()); } catch (Exception e) { e.printStackTrace(); } } } import org.kuali.khc.http.*; import java.net.URI; public class HttpClientSecureConfigExample { public static void main(String[] args) { try { HttpClientConfig config = HttpClientConfig.newBuilder() .setConnectTimeout(5000) .setTlsVersion(TLSVersion.TLSv1_2) .setTlsCipherSuites(TLSCipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA) .build(); HttpConnection connection = HttpConnection.newBuilder() .setUri(new URI("https://example.com/api")) .setMethod(HttpMethod.POST) .setBody("{\"param1\":\"value1\"}") .setConfig(config) .build(); HttpResponse response = connection.execute(); System.out.println("Response Code: " + response.getResponseCode()); System.out.println("Response Body: " + response.getBody()); } catch (Exception e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文