2015-01-15 2 views
0

사용자 이름/비밀번호가 포함 된 권한 부여 헤더가 특정 문자 집합을 사용할 수 있도록 헤더에 사용할 charset을 지정하는 방법에 대해 httpclient 4.3.3 API를 조회했습니다. UTF-8 또는 iso-8859-1과 같은 사용되지 않는 3.x API는 다음과 같습니다.httpclient 4.3.x에서 작동하지 않는 non-ascii 자격 증명 사용

httpMethodInstance.getParams().setHttpElementCharset("iso-8859-1"); 

4.3.3의 해당 API는 ConnectionConfig에 있습니다. 내가

HttpClientBuilder builder = HttpClientBuilder.create(); 
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); 
     credentialsProvider.setCredentials(AuthScope.ANY, 
      new UsernamePasswordCredentials(username, password)); 

builder.setDefaultCredentialsProvider(credentialsProvider); 

ConnectionConfig connectionConfig = ConnectionConfig.custom() 
     .setCharset(Charset.forName("iso-8859-1")).build(); 
BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(
     registryBuilder.build()); 
connManager.setConnectionConfig(connectionConfig); 
builder.setConnectionManager(connManager); 



HttpHost target = new HttpHost(host, port, scheme); 
HttpContext localContext = new BasicHttpContext(); 
localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); 

CloseableHttpClient httpclient = builder.build(); 
CloseableHttpResponse response = httpclient.execute(target, request, localContext); 

를 사용하여 시도 코드 그러나 인증 헤더를 통해 전송 자격 증명의 인코딩 된 값이 자격 증명을 지정된 캐릭터 세트 "ISO-8859-1"을 사용하여 인코딩 있지 않음을 나타냅니다 base64로입니다 다음. ConnectionConfig.setCharset()은 http 헤더 문자 집합을 설정하는 데 사용할 올바른 방법입니까? 그렇지 않은 경우 4.3.x에서 사용되지 않는 setHttpElementCharset()과 정확히 일치하는 것은 무엇입니까?

아파치 메일 보관 파일 http://mail-archives.apache.org/mod_mbox/hc-dev/201407.mbox/%[email protected]%3E은 쉽게 지원되지 않으며 BasicSchemeFactory 사용을 제안하지만 사용하는 문자셋을 지정하는 방법/위치를 파악할 수 없다는 것을 나타냅니다.

답변

0

사용자 정의 charset 인코딩은 일부 인증 스키마 (예 : 기본 및 다이제스트)에 적용 가능하며 다른 사용자에게는 적용되지 않습니다. 글로벌 사용자 정의 인증 charset 매개 변수는 캐릭터 세트가있다

자격 증명은 사용자 정의 인증 방식 공장을 사용하여 체계별로 구성 할 나쁜 생각이었다

Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() 
      .register(AuthSchemes.BASIC, new BasicSchemeFactory(Consts.UTF_8)) 
      .register(AuthSchemes.DIGEST, new DigestSchemeFactory(Consts.UTF_8)) 
      .register(AuthSchemes.NTLM, new NTLMSchemeFactory()) 
      .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()) 
      .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()) 
      .build(); 
CloseableHttpClient httpclient = HttpClients.custom() 
     .setDefaultAuthSchemeRegistry(authSchemeRegistry) 
     .build();