Reputation: 309
I have a custom certificate on Android and need to know how to attach it to make the post call. I have already made successful POSTs using HTTP, but I do not know what steps to take with HTTPS. How do I load the certificate?
Upvotes: 0
Views: 57
Reputation: 1006549
If your minSdkVersion
is 24 or higher, you can use Android 7.0's network security configuration to handle this. You package your certificate as a raw
resource, create an XML resource indicating to use that certificate, and add an attribute in the manifest to teach Android to use those rules.
If your minSdkVersion
lower than 24, but 17 or higher, you can use my backport of the network security configuration code.
If your minSdkVersion
is lower than 17, you will need to follow conventional Java instructions for using self-signed certificates. The details of how to do that will vary by HTTP client API that you are using (HttpURLConnection
, OkHttp, etc.). For example, this blog post outlines how to do that for OkHttp.
Upvotes: 1