-1

我正在尝试编写一个 Android 应用程序,它允许我从保存我的工作名册https://www.blahblahblahcompany.com/Rostering/exportRoster.aspx的网站读取文本

这可能吗?我可以通过网站验证自己的身份,然后下载源代码吗?

有问题的网站还可以将名册导出为 .xls 文件

相关页面的屏幕截图 http://img528.imageshack.us/img528/9954/rosterf.png

4

2 回答 2

0

在 Android Web 浏览器中,转至工具 > 选项 > 加密 > 查看证书以查看支持的证书提供程序列表。只要您从受支持的提供商处购买证书,您就可以做到。 这是一个可能有一些线索的堆栈答案。

于 2012-06-18T04:22:43.250 回答
0

我不知道我是否得到了你真正想做的事情,但我敢肯定,至少,你需要一些 Get/Post 操作来执行身份验证过程并检索数据/信息。请检查以下方法:

public StringBuilder post(String url, List<NameValuePair> nvps) {
    try {
        HttpPost httppost = new HttpPost(url);
        // if there is cookies, set then
        if (cookies != null && cookies.size() > 0) {
            String cookieString = "";
            for (int i = 0; i < cookies.size(); ++i) {
                cookieString += cookies.get(i).getName() + "=" + cookies.get(i).getValue() + "; ";
            }
            cookieString += "domain=" + Constants.BaseUrl + "; " + "path=/";
            httppost.addHeader("Cookie", cookieString);
        }
        // connection timeout options
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, Constants.timeoutConnection);
        HttpConnectionParams.setSoTimeout(httpParameters, Constants.timeoutSocket);
        // setup the post method
        DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = httpClient.execute(httppost);
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        StringBuilder builder = new StringBuilder();
        for (String line = null; (line = reader.readLine()) != null;)
            builder.append(line).append("\n");
        // set cookies
        List<Cookie> incomingCookies = httpClient.getCookieStore().getCookies();
        for (int i = 0; incomingCookies != null && i < incomingCookies.size(); i++) {
            cookies.add(incomingCookies.get(i));
        }
        return builder;
    } catch (UnsupportedEncodingException e) {
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    } catch (Exception e) {
    }
    return null;
}

上面的方法在url字符串参数中执行一个帖子,使用对值nvps作为 header 的参数。请注意,Constants类是您为 WebService 声明静态字符串(例如 API 条目)的类,字段cookies是保存会话问题的 Cookie 列表。此方法会将您的 POST 请求的结果作为字符串构建器对象返回。基本上,它是一种通用方法,可以在多种情况下使用,您应该进行少量调整以适应任务。这是您可以用来进行身份验证的内容。

还有一个重要的方法,Http GET:

public StringBuilder get(String url) {
    try {
        HttpGet httpget = new HttpGet(url);
        // if there is cookies, set then
        if (cookies != null && cookies.size() > 0) {
            String cookieString = "";
            for (int i = 0; i < cookies.size(); ++i) {
                cookieString += cookies.get(i).getName() + "=" + cookies.get(i).getValue() + "; ";
            }
            cookieString += "domain=" + Constants.BaseUrl + "; " + "path=/";
            httpget.addHeader("Cookie", cookieString);
        }
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, Constants.timeoutConnection);
        HttpConnectionParams.setSoTimeout(httpParameters, Constants.timeoutSocket);
        DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpResponse response = httpClient.execute(httpget);
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        StringBuilder builder = new StringBuilder();
        for (String line = null; (line = reader.readLine()) != null;)
            builder.append(line).append("\n");
        // set cookies
        List<Cookie> incomingCookies = httpClient.getCookieStore().getCookies();
        for (int i = 0; incomingCookies != null && i < incomingCookies.size(); i++) {
            cookies.add(incomingCookies.get(i));
        }
        return builder;
    } catch (UnsupportedEncodingException e) {
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    } catch (Exception e) {
    }
    return null;
}

这一个执行类似的步骤顺序,但目的非常不同。考虑到您已经通过身份验证或不需要身份验证过程,这一目标是检索信息。它将请求的数据作为字符串生成器返回。

请注意,除了这些方法非常通用外,您还必须仔细检查您请求的网页中使用的过程是什么。希望它能以某种方式帮助你!;-)

于 2012-06-18T04:37:08.343 回答