通过 Android 应用程序登录 https 网站 [英] Performing login to https website via Android app

查看:37
本文介绍了通过 Android 应用程序登录 https 网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我对此很陌生.我是 Android、asp、javascript 甚至 http 的新手.

First off, I'm pretty newb at this. I'm new to Android, to asp, to javascript, to http even.

我正在尝试构建一个 Android 应用程序,允许我登录到我学校的网站并从中提取数据,最终我希望做一些事情,比如将我的时间表数据插入到 Android 的日历条目中.但是我无法登录.

I'm trying to build an Android app that allows me to login to my school's website and pull data off it, ultimately I hope to do something like insert my timetable's data into Android's calendar entries. However I'm having trouble logging in.

这是网站:https://sso.wis.ntu.edu.sg/webexe88/owa/sso_login2.asp

我目前正在做的是对上述 URL 进行 http POST,我希望被重定向到 hhttps://wish.wis.ntu.edu.sg/pls/webexe/aus_stars_check.check_subject_web2这将显示我的时间表.

What I'm doing currently is doing a http POST to the above-mentioned URL and I'm hoping to be redirected to hhttps://wish.wis.ntu.edu.sg/pls/webexe/aus_stars_check.check_subject_web2 which will display my timetable.

查看网页源码并在网上搜索了一番后,目前我的代码如下:

So far my code is as follows after viewing the webpage's source and searching quite a bit on the Internet:

private void start_login(String[] array) {
    // TODO Auto-generated method stub
    Toast.makeText(this, "Logging in...", Toast.LENGTH_LONG).show();

    WebView wv = new WebView(this);     
    this.setContentView(wv);

    try {

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
        nameValuePairs.add(new BasicNameValuePair("UserName", <my username here>));
        nameValuePairs.add(new BasicNameValuePair("PIN", <my password here>));
        nameValuePairs.add(new BasicNameValuePair("Domain", "STUDENT"));
        nameValuePairs.add(new BasicNameValuePair("p2", "https://wish.wis.ntu.edu.sg/pls/webexe/aus_stars_check.check_subject_web2"));

        wv.loadData(CustomHttpClient.executeHttpPost(URL, nameValuePairs), "text/html", "utf-8");

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}// end start_login

这就是登录功能.

我使用的 CustomHttpClient 多亏了这个人:http://www.newtondev.com/2010/07/27/making-http-requests-using-google-android/

The CustomHttpClient I'm using is thanks to this guy: http://www.newtondev.com/2010/07/27/making-http-requests-using-google-android/

到目前为止,我没有得到任何结果.我究竟做错了什么?我是在 ArrayList 中缺少值,还是我的 URL 都错了?

So far I'm not getting any results. What am I doing wrong? Am I missing values in the ArrayList, or have I got the URL all wrong?

推荐答案

下面的代码处理 https 并为 https url 提供 httpsclient .. 你需要 httpsclient 来向 https url 发出请求.

Below code handles https and gives httpsclient for https url .. you need httpsclient to make request to https urls.

下面的代码可能对你有帮助:

Might below code is of help to you:

public DefaultHttpClient getClient() 
   {
        DefaultHttpClient ret = null;

        //sets up parameters
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "utf-8");
        params.setBooleanParameter("http.protocol.expect-continue", false);

        //registers schemes for both http and https
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
        sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        registry.register(new Scheme("https", sslSocketFactory, 443));

        ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
        ret = new DefaultHttpClient(manager, params);
        return ret;
    }

这篇关于通过 Android 应用程序登录 https 网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆