我需要调用"HTTPS"api并将JSON params传递给服务器.
现在我想这样:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://myapi call goes here...");
httppost.setHeader("Content-Type", "application/json");
try
{
JSONObject j = new JSONObject();
j.put("email", "my email value goes here");
StringEntity s = new StringEntity(j.toString());
httppost.setEntity(s);
HttpResponse response = httpclient.execute(httppost);
/* Checking response */
if(response != null)
{
responseBody = EntityUtils.toString(response.getEntity());
}
if(responseBody.equals("ok"))
{
}
}
catch (final Exception e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但它给了我例外:SSL Peer未经验证:没有同行证书.
请注意,我必须只使用HTTPS来拨打api.
有人有什么想法?