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

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

问题描述

首先,我是pretty的福利局在此。我是新来的Andr​​oid,到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

我在做什么目前正在做一个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.

到目前为止,我的code是查看网页的源代码,并搜索了不少在互联网上后如下:

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

这就是登录功能。

That's the login function.

我正在使用的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中缺失值,或者有我的网址都错了?

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?

推荐答案

下面code处理HTTPS并给出httpsclient为HTTPS URL ..你需要httpsclient做出请求HTTPS URL中。

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

强权低于code是对您有所帮助:

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天全站免登陆