Convert any web page content to UTF-8 using http4

I am using apache camel-http4.

I want to convert the contents of any web page to UTF-8, I use http4 as my httpClient.

I created my class HttpClientConfigurer, which implements org.apache.camel.component.http4.HttpClientConfigurer.

I set HTTP_CONTENT_CHARSET to Consts.UTF_8, as in the configureHttpClient method.

   public void configureHttpClient(HttpClient client) {
    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1).setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,Consts.UTF_8);
}

But that did not work.

I also tried setting the header for UTF-8 like this,

  setHeader(Exchange.HTTP_CHARACTER_ENCODING, constant('UTF-8'))

inside my route, but that didn't work either.

Any idea on how to convert any page encoding to UTF-8 using http4.

+3
source share
1 answer

, . , , . ,

  • ( )
  • utf-8. .convertBodyTo(String.class, "UTF-8") ( 1. , )
  • , Exchange.HTTP_CHARACTER_ENCODING
0

All Articles