使用HTTP POST方法与jsoup asp.NET登录 [英] asp.NET login using HTTP post method with jsoup

查看:535
本文介绍了使用HTTP POST方法与jsoup asp.NET登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近试图建立一个Android应用程序供我上学的朋友,这样他们就不必使用Web浏览器,但一个简单的应用程序,以检查其更新的成绩和考试的时间表,但因为学校不会给予许可,使用其数据库的唯一的方法是做HTML解析。 所以我发现这个库Jsoup和示例,并开始写我自己的code,但它总是带给我的登录页面的页面源代码(它不登陆的话)

I am recently trying to develop a android app for my school friends so they do not have to use a web browser but an simple app to check their updated grades and exam schedule but since the school wont give permission to use their DB the only method is to do HTML parsing. so I found this library Jsoup and an example and started writing my own code but it always brings me the page source of login in page (It doesnt log in at all)

public Document getHTMLsoure() {
Document doc=null;
    try {
         doc = Jsoup.connect("http://karinca.meliksah.edu.tr")
                 .data("ctl00$ContentPlaceHolder1$txtKullaniciAdi","usernm")
                .data("ctl00$ContentPlaceHolder1$txtSifre", "passwd")
                .data("ctl00$ContentPlaceHolder1$btnLogin", "Giriş")


                .userAgent("Mozilla")

                .post();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

返回文档; }

return doc; }

推荐答案

请检查一下。
结果Kullanıcı名称亚达şifrehatası!

Please check it.
Result Kullanıcı adı yada şifre hatası !

Response res = Jsoup
        .connect("https://karinca.meliksah.edu.tr/View/Login")
        .userAgent("Mozilla")
        .execute();

Document doc = res.parse();

String eventArgument = doc.select("input[name=__EVENTARGUMENT]").val();
String viewState = doc.select("input[name=__VIEWSTATE]").val();
String viewStateGenerator = doc.select("input[name=__VIEWSTATEGENERATOR]").val();
String eventValidation = doc.select("input[name=__EVENTVALIDATION]").val();
String asyncPost = "true";

String ct = "";

String body = doc.body().html();

int indexOf = body.indexOf("Sys.WebForms.PageRequestManager._initialize(");;
if(indexOf > -1){

    int indexEnd = body.substring(indexOf).indexOf("');");

    if(indexEnd > -1){

        String temp  = body.substring(indexOf, indexOf+indexEnd);
        int indexStart = temp.lastIndexOf("'");
        ct = temp.substring(indexStart+1,temp.length());
    }
}

Document   doc1 = Jsoup.connect("https://karinca.meliksah.edu.tr/View/Login.aspx")

    .referrer("https://karinca.meliksah.edu.tr/View/Login")
    .cookies(res.cookies())
    .data(ct+"$ContentPlaceHolder1$ScriptManager2",ct+"$ContentPlaceHolder1$UpdatePanel1|"+ct+"$ContentPlaceHolder1$btnLogin")
    .data(ct+"$ContentPlaceHolder1$txtKullaniciAdi","usernm")
    .data(ct+"$ContentPlaceHolder1$txtSifre", "passwd")
    .data("__EVENTTARGET",ct+"$ContentPlaceHolder1$btnLogin")
    .data("__EVENTARGUMENT",eventArgument)
    .data("__VIEWSTATE",viewState)
    .data("__VIEWSTATEGENERATOR",viewStateGenerator)
    .data("__EVENTVALIDATION",eventValidation)
    .data("__ASYNCPOST",asyncPost)
    .userAgent("Mozilla")
    .post();


System.out.println(doc1.html());

这篇关于使用HTTP POST方法与jsoup asp.NET登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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