Este team redactor ha pasado mucho tiempo buscando para darle solución a tu búsqueda, te brindamos la respuestas y deseamos servirte de mucha ayuda.
Ejemplo: ejemplo de proxy httpclient de Java
importorg.apache.http.HttpHost;importorg.apache.http.HttpResponse;importorg.apache.http.auth.AuthScope;importorg.apache.http.auth.UsernamePasswordCredentials;importorg.apache.http.client.CredentialsProvider;importorg.apache.http.client.config.RequestConfig;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.impl.client.BasicCredentialsProvider;importorg.apache.http.impl.client.CloseableHttpClient;importorg.apache.http.impl.client.HttpClientBuilder;importorg.apache.http.impl.client.HttpClients;publicclassProxyAuthenticationExamplepublicstaticvoidmain(String[] args)throwsException//Creating the CredentialsProvider objectCredentialsProvider credsProvider =newBasicCredentialsProvider();//Setting the credentials
credsProvider.setCredentials(newAuthScope("example.com",80),newUsernamePasswordCredentials("user","mypass"));
credsProvider.setCredentials(newAuthScope("localhost",8000),newUsernamePasswordCredentials("abc","passwd"));//Creating the HttpClientBuilderHttpClientBuilder clientbuilder =HttpClients.custom();//Setting the credentials
clientbuilder = clientbuilder.setDefaultCredentialsProvider(credsProvider);//Building the CloseableHttpClient objectCloseableHttpClient httpclient = clientbuilder.build();//Create the target and proxy hostsHttpHost targetHost =newHttpHost("example.com",80,"http");HttpHost proxyHost =newHttpHost("localhost",8000,"http");//Setting the proxyRequestConfig.Builder reqconfigconbuilder=RequestConfig.custom();
reqconfigconbuilder = reqconfigconbuilder.setProxy(proxyHost);RequestConfig config = reqconfigconbuilder.build();//Create the HttpGet request objectHttpGet httpget =newHttpGet("/");//Setting the config to the request
httpget.setConfig(config);//Printing the status lineHttpResponse response = httpclient.execute(targetHost, httpget);System.out.println(response.getStatusLine());
Recuerda que tienes la capacidad de aclarar si te fue de ayuda.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)