开发者

httpget not working past "execute"

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


You should definitely provide the stacktrace to be sure, but most probably your phone doesn't trust the CA that issued iphone-radar.com's SSL certificate: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US. (it's not in Gingerbread's trust store)

Search SO to find how to add this certificate to your trust store, there are multiple posts about this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜