@Retention(value=CLASS)
@Target(value=FIELD)
public @interface HttpsClient
Use this annotation to inject an HttpClient instance with the specified KeyStore and TrustStore configured to perform an HTTPS request.
All the parameters are optional:
R.raw.cacerts.bks
Typically your servers trusted certificates
(public key, Root Chain Authority etc)changeit
)changeit
)true
) If false, Hostname in certificate (DN)
must match the URL.Example :@EBean public class MyBean { @HttpsClient(trustStore = R.raw.cacerts, // trustStorePwd = "changeit", // keyStore = R.raw.client, // keyStorePwd = "secret", // allowAllHostnames = false) 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(); } }
Modifier and Type | Optional Element and Description |
---|---|
boolean |
allowAllHostnames |
int |
keyStore |
java.lang.String |
keyStorePwd |
java.lang.String |
keyStoreResName |
int |
trustStore |
java.lang.String |
trustStorePwd |
java.lang.String |
trustStoreResName |
public abstract int trustStore
public abstract java.lang.String trustStoreResName
public abstract java.lang.String trustStorePwd
public abstract int keyStore
public abstract java.lang.String keyStoreResName
public abstract java.lang.String keyStorePwd
public abstract boolean allowAllHostnames
Copyright © 2010-2014. All Rights Reserved.