Hi I saw an example on StackOverflow which 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 similar to this. I tried to use the same code but I couldn't find the Base64Encoder class anywhere. Im using httpclient-4.1.2.jar and httpcore-4.1.2.jar. Can someone help me with this?
Base64 is a binary-to-text encoding scheme. It represents binary data in a printable ASCII string format by translating it into a radix-64 representation.
Java 8 introduced the Base64 class, which is available in the java. util. Base64. The Base 64 is a strategy or scheme to encode the binary data into encoded text format, which can be easily sent over the internet without corrupted and data loss with securely.
You can encrypt and decrypt your data by using provided methods. You need to import java. util. Base64 in your source file to use its methods. This class provides three different encoders and decoders to encrypt information at each level.
Instances of Base64. Encoder class are safe for use by multiple concurrent threads. Unless otherwise noted, passing a null argument to a method of this class will cause a NullPointerException to be thrown.
A Base64 en/decoder has long been missing from the Java APIs, so you'll have to find a good 3rd party one, e.g. Apache Commons Codec, iHarder Base64, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With