DocumentatieDoelontwikkelaarsgids

Aangepaste HTTP Client Configuration (Java)

Laatst bijgewerkt: 27 juli 2023
  • Onderwerpen:
  • APIs/SDKs

Gemaakt voor:

  • Ontwikkelaar

Als de toepassing die de SDK uitvoert een aangepaste HTTP-client nodig heeft om functies in te schakelen zoals SSL configureren of standaardheaders aan aanvragen toevoegen, TargetClient zal moeten worden gevormd gebruikend ClientConfig.builder().httpClient():

Standaard aangepaste HTTP-clientconfiguratie

De SDK biedt momenteel ondersteuning voor HTTP-clients die de org.apache.http.client.HttpClient interface.

Basisimplementatie

CloseableHttpClient httpClient = HttpClients.custom().build();
ClientConfig clientConfig = ClientConfig.builder()
    .client("acmeclient")
    .organizationId("1234567890@AdobeOrg")
    .httpClient(httpClient)
    .build();
TargetClient targetClient = TargetClient.create(clientConfig);

Aangepaste HTTP-clientconfiguratie met SSL-configuratie

Hier is een voorbeeld van hoe te om SSL in te vormen TargetClient door de HttpClient worden doorgegeven aan de ClientConfig. Het volgende codefragment gebruikt klassen uit het org.apache.http.conn.ssl pakket voor SSL-configuratie.

SSL-implementatie

SSLContext context = SSLContextBuilder.create().build();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(context);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
ClientConfig clientConfig = ClientConfig.builder()
    .client("acmeclient")
    .organizationId("1234567890@AdobeOrg")
    .httpClient(httpClient)
    .build();
TargetClient targetClient = TargetClient.create(clientConfig);
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3