-
Notifications
You must be signed in to change notification settings - Fork 0
Simple HTTPS
Since AndroidAnnotations 2.6
The @HttpsClient simplifies HTTPS requests by configuring the KeyStore, TrustStore and Hostname Verification on the HttpClient instance.
All the parameters are optionals.
Here is the complete form if you want to achieve Client Auth:
@HttpsClient(trustStore=R.raw.cacerts,
trustStorePwd="changeit",
keyStore=R.raw.client,
keyStorePwd="secret",
allowAllHostnames=false)
HttpClient httpsClient;-
trustStore: int, Resource id of your trust store file ex
R.raw.cacerts.bksTypically your servers trusted certificates (public key, Root Chain Authority etc) -
trustStorePwd: String, Your TrustStore password (default is changeit)
-
keyStore: int, Resource id of your keystore Usually your private key (client certificate)
-
keyStorePwd: Your KeyStore password (default is changeit)
-
allowAllHostnames: boolean, if true, authorizes any TLS/SSL hostname (default
true) If false, Hostname in certificate (DN) must match the URL
Note: Prior to ICS, Android accept [Key|Trust]store only in BKS format (Bouncycastle Key Store)
This is useful if your remote server use a selfsigned certificate or a certificate issued by a private certificate authority
@HttpsClient(trustStore=R.raw.mycacerts,
trustStorePwd="changeit")
HttpClient httpsClient;If you do not specify a truststore file, the annotation will use the default android truststore located at /system/etc/security/cacerts.bks which allows you to connect to a server signed with one of the trusted root CAs (Thawte, verisign etc.)
@HttpsClient
HttpClient httpsClient;@EActivity
public class MyActivity extends Activity {
@HttpsClient(trustStore=R.raw.cacerts,
trustStorePwd="changeit",
hostnameVerif=true)
HttpClient httpsClient;
@AfterInject
@Background
public void securedRequest() {
try {
HttpGet httpget = new HttpGet("https://www.verisign.com/");
HttpResponse response = httpsClient.execute(httpget);
doSomethingWithResponse(response);
} catch (Exception e) {
e.printStackTrace();
}
}
@UiThread
public void doSomethingWithResponse(HttpResponse resp) {
Toast.makeText(this, "HTTP status " + resp.getStatusLine().getStatusCode(), Toast.LENGTH_LONG).show();
}
}14/06/2012 The 2.6 release is out
- Get started!
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow