Where can I find the Base64Encoder class?

Hi, I saw an example in StackOverflow that had this code:

String encoding = Base64Encoder.encode ("test1:test1"); HttpPost httppost = new HttpPost("http://host:post/test/login"); httppost.setHeader("Authorization", "Basic " + encoding); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); 

I have a task like this. I tried using the same code but could not find the Base64Encoder class anywhere. I am using httpclient-4.1.2.jar and httpcore-4.1.2.jar. Can someone help me with this?

+6
source share
3 answers

I think you need to have the commons codec also use Base64 encoding with HttpClient. Here's a link. Link to Commons Codec

+4
source

Base64 en / decoder has long been missing from the Java API, so you will need to find a good third-party, for example. Apache Commons Codec , iHarder Base64 , etc.

+6
source

Since maerics asked me:

Since I think Java6 is actually a DatatypeConverter class, which is part of JAXB.

Two static public methods parseBase64Binary and printBase64Binary . Also note that it is defined in java.lang , so it is an official part of the JDK. You can use it, but I personally like the commons option better, since it does not return a string when decoding base64 material.

+2
source

Source: https://habr.com/ru/post/905329/


All Articles