0

我正在尝试制作一个应用程序,该人可以连接到他们的特定网站,然后可以从中访问数据。第一页要求他们输入网址。然后我解析这个并需要验证 url 的存在,以便我可以将它们移动到登录屏幕。我该怎么做呢?我正在尝试 HttpURLConnections 但我运气不佳。想法?

4

1 回答 1

0

试试下面的代码:

try {

int status = 0;
try {
    HttpURLConnection httpConnection = (HttpURLConnection) new URL(
    "http://www.google.com").openConnection();
            httpConnection.setRequestMethod("HEAD");
            Log.e("StatusCode",httpConnection.getResponseCode());

            if ((httpConnection.getResponseCode() == 200)||(httpConnection.getResponseCode() == 302)) {
                status = 1;
            }

        } catch (Exception ex) {}
        if (status == 1) {
            Log.e("WebSite","Found");
        } else {
            Log.e("WebSite","NotFound");
        }

} catch (Exception ex1) {
Log.e("Error",ex1.getMessage().toString());
}
于 2013-08-08T11:36:36.757 回答