If your code is similar to the following you can
experience the problem:
byte[] rawupw = (new
String("ibmuser:ibmuser")).getBytes();
String auth = "Basic " + new sun.misc.BASE64Encoder().encode(rawupw);
uc.setRequestProperty("Authorization", auth);
This code works on a machine that uses ASCII encoding, but encounters
problems on the z/OSĀ® platform. The code creates an array of bytes in
EBCDIC format when it runs on z/OS. (Since there were no arguments passed
to the getBytes() call, the JavaTM Virtual Machine (JVM) takes
the system default). It then builds the authorization header by using the
EBCDIC bytes. Any request made with this header causes an HTTP server to
return an error. The error occurs because an HTTP server receiving an
authorization header expects the Base64 encoded data to be in ASCII, not
EBCDIC.
In this particular case, the customer used the IBM HTTP Server on the z/OS
platform
Resolve the problem by coding your servlet this way:
byte[] rawupw = (new
String("ibmuser:ibmuser")).getBytes("ISO-8859-1");
String auth = "Basic " + new sun.misc.BASE64Encoder().encode(rawupw);
uc.setRequestProperty("Authorization", auth);
Note: the getBytes() call now overrides the default encoding,
which used ASCII bytes. |