简体   繁体   中英

Logging in to website from android app to retrieve and parse information

I've been researching networking in android and have become familiar with the basic concepts. However, I've recently been working on an app intended for use by my school as a gradebook/assignment display of sorts. My school uses the following online gradebook: https://parents.mtsd.k12.nj.us/ , and currently I'm trying to allow students to input their login credentials into my app which will then try to retrieve their respective information and display it in a gridview. However, I have never attempted to log in to a website from an android app before parsing data (I have gone through several similar questions but I am still a little confused)

Any help is appreciated!

[edit] After logging in I will use import.io to display gradebook data, website does not have api

If I understand You clearly u need to :

  1. Connect to site using HttpURLConnection with user creditentials (do Post request to login page)
  2. Obtain cookies from request (my favorite way is to parse - copy appropriate header field)
  3. Use obtained cookies with HttpURLConnection.setRequestProperty("Cookie",obtainedCookies) and do another request(to user data page).
  4. Get input stream
  5. Parse stream (to obtain Document "html" u can use jsoup example: Document doc = JSoup.parse(stream, null, "");

  6. Show data

GUIDELINES:

cookie how to

Most useful example

Caution:

-any http requests needs to be done outside main thread (ui thread) - u can use async task for this or intent service

EDIT on questions:

you ask whether to use Jsoup to handle connection?

my answer is NO!

Jsoup is a PARSER by using HttpURLConnection u gain full control over HTTP request so for example u can handle some specyfic exceptions or request propertiers which jsoup is not capable! from my experience after a while I start to disassemble the libraries and learn from them the basics and use parts of them in my code!

您可以使用具有登录名和密码字段的自定义HTML文件创建WebView,然后让HTML文件运行与网站相同的脚本以将其登录。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM