For making API's call more secure we need to implement HTTP Basic Authorization Header.
In order to set the authorization, first we need to encode the secret key or API key like this:-
public static String getB64Auth(String key) {
String ret = "Basic " +Base64.encodeToString(key.getBytes(), Base64.DEFAULT);
return ret;
}
Now set the Base64Encoded secret key in Header like this:-
// If you are using Apache HttpCLient:
request.setHeader("Authorization", basicAuth);
// If you are using HttpUrlConnection:
connection.setRequestProperty ("Authorization", basicAuth);
0 Comment(s)