Your approach is OK, but can be improved by adding more "security":
Use Basic Auth in the login url, ie send user and password format "user:password" coded in Base64 on the request header.
Example:
Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myuser","mypass".toCharArray());
}});
HttpURLConnection c = (HttpURLConnection) new URL(url).openConnection();
c.setUseCaches(false);
c.connect();
or you can simply add a request Property to the connection:
c.setRequestProperty("Authorization", "basic " +
Base64.encode("myuser:mypass".getBytes(), Base64.NO_WRAP));
- For the other Urls, send the token in the request header and always make sure that the token is encrypted and not only encoded in Base64 which allows anyone to reuse a token even if it is expired. You can use the header "Authorization" to that end.
Finally, avoid sending any sensitive information without being encrypted, let alone in the URL path.
Is this syntax Java language? Can you tell me an example in javascript? What I understood you meant was to send the information in the http header with encrypted data? Correct?
– Augusto Junior
Yes, the example is java and Android. In Javascript is equal, Voce will make an Ajax call passing the encrypted Headers.
– Gyowanny Pessatto Queiroz