-
Notifications
You must be signed in to change notification settings - Fork 0
Simple HTTPS
The @HttpsClient Simplify HTTPS requests by configuring the KeyStore, TrustStore and Hostname Verification.
All the parameters are optionals
This is the complete form if you want to achieve Client Auth
@HttpsClient(trustStore=R.raw.cacerts,
trustStorePwd="changeit",
keyStore=R.raw.client,
keyStorePwd="secret",
hostnameVerif=true)
HttpClient mHttps;-
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)
-
hostnameVerif: boolean, Turn on or off strict hostname verification (default false) Hostname in certificate (DN) must match the URL
Note: Until 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 mHttps;If you don't specify a truststore file, the annotation will use the default android truststore located at /system/etc/security/cacerts.bks it allow you to connect to a server signed with one of the trusted root CAs (Thawte, verisign etc.)
@HttpsClient
HttpClient mHttps;@EActivity(R.layout.main)
public class HttpsClientSampleActivity extends Activity {
@HttpsClient(trustStore=R.raw.cacerts,
trustStorePwd="changeit",
hostnameVerif=true)
HttpClient mHttps;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
secureConnection();
}
@Background
public void secureConnection () {
try {
HttpGet httpget = new HttpGet("https://www.verisign.com/");
HttpResponse response = mHttps.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