Is it possible to set the user name and password on an HTAccess certificate directly from my code rather than have the user do it from the HTAccess prompt?

Bogdan Sheptunov

Yes. This is the code for BASIC http authorization:

// use this to encode the username/password
private String encodeAuthorization String username, String password)
    String authorization = username + ":" + password;
    sun.misc.BASE64Encoder enCoder = new sun.misc.BASE64Encoder();
    return "Basic " + enCoder.encode(authorization.getBytes());

// insert this piece into setting the connection properties, where encodedAuthorization is a result of the function given above:
connection.setRequestProperty("Authorization", encodedAuthorization);
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact