my program is supposed to go to a website and depending on the id(4e3f2c6659f25a0f8400000b), it will get a json string. For some reason, this program will not go past the client.execute line and throws an IOException. This function works for my other programs that need to extract information from a website. If you go to https://iphone-radar.com/accounts/4e3f2c6659f25a0f8400000b you can see the type of line I want to copy. Here is my code, I hope you can help me find out why this is happening. Thank you.
public String getText(String uri) {
HttpClient client1 = new DefaultHttpClient();
HttpGet request = new HttpGet("https://iphone-radar.com/accounts/4e3f2c6659f25a0f8400000b");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String response_str = client1.execute(request, responseHandler);
return response_str;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
It seems like this exception is about untrusted certificate. This will happen when you’re trying to access a HTTPS with an expired certificate, or a self-signed certificate. On a browser, a popup window will show asking us whether to trust or not. In an application’s process then we need to add some codes to ignore the untrusted SSL certificate, or to update the JVM certificates so that it recognizes the certificate.
Reference: Disabling Certificate Validation in an HTTP Connection