Pregunta

I am using HTTPClient Fluent API version 4.3.2 to send multiple request to various addresses defined by user. Each address will use its particular proxy setting. Below is my current code:

try {

            final Executor executor = Executor.newInstance().auth(proxy, userName, passWord);
            System.out.println(executor.execute(Request.Get(uri).viaProxy(proxy)).returnResponse().getStatusLine());
        } catch (final Exception e) { 
            e.printStackTrace(); 
        }

I am facing a problem, when I connect to Address 1 with Proxy 1 (correct value of proxy username and proxy password), the request send properly as expected.

But when I add Address 2 with Proxy 1 (wrong value of proxy username and proxy password), with the expectation is request will fail, but it still connect successfully.

I though that after send request through a proxy, the very first proxy setting was cached somewhere in JVM, and I can not set another proxy setting for another request.

Is there any solution for this?

¿Fue útil?

Solución

Trying setting proxy prior to request execution

Executor executor = Executor.newInstance().auth(proxy, userName, passWord);
System.out.println(executor
  .viaProxy(proxy)
  .execute(Request.Get(uri))
  .returnResponse().getStatusLine());
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top