Apache HttpClient 4.1 - Proxy Authentication

前端 未结 7 1126
走了就别回头了
走了就别回头了 2020-11-30 03:07

I\'ve been trying to configure the user and password for proxy authentication from the configured properties while using Apaches HttpComponent\'s httpclient, but with no suc

7条回答
  •  日久生厌
    2020-11-30 04:01

    For HttpClient 4.5 and per request authentication:

    HttpContext httpContext = new BasicHttpContext();
    AuthState authState = new AuthState();
    
    authState.update(new BasicScheme(), new UsernamePasswordCredentials("userName", "password"));
    httpContext.setAttribute(HttpClientContext.PROXY_AUTH_STATE, authState);
    CloseableHttpResponse httpResponse = httpClient.execute(httpRequest, httpContext);
    

提交回复
热议问题