You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Jsoup实现Webix框架站点身份认证失败,求解决方案

Webix框架站点授权认证故障排查求助

我正在通过代码实现站点授权功能,目前遇到故障无法完成认证,特寻求技术帮助。目标站点登录界面基于Webix框架构建。

登录页页面结构

登录界面结构

<div class="webix_win_content">
<div class="webix_win_head">
    <div class="webix_view webix_header webix_win_title" view_id="$template1" style="width: 300px; height: 26px;">
        <div class=" webix_template">Auth</div>
    </div>
</div>
<div class="webix_win_body">
    <div class="webix_view webix_form webix_layout_form" role="form" view_id="myForm" style="width: 300px; height: 511px;">
        <div class="webix_scroll_cont">
            <div class="webix_view webix_control webix_el_richselect" view_id="$richselect1" style="border-width: 0px; margin-left: 12px; margin-top: 4px; width: 276px; height: 42px;">
                <label style="text-align:left; line-height:13px; display:block;" onclick="" for="x1631034732210" class="webix_inp_top_label ">
                    <font size="+2">OR</font> Log in with a USPTU account
                </label>
                <div class="webix_el_box" style="width:276px; height:26px">
                    <div class="webix_inp_static" role="combobox" aria-label="<font size=+2>ИЛИ</font> Log in with a USPTU account" tabindex="0" onclick="" style="line-height:18px;width: 272px; text-align: left;" aria-autocomplete="list" aria-expanded="false" aria-live="assertive" aria-atomic="true">Login</div>
                    <span style="height:20px;padding-top:0px;" class="webix_input_icon wxi-menu-down"></span>
                </div>
            </div>
            <div class="webix_view webix_control webix_el_text" view_id="username" style="border-width: 0px; margin-left: 12px; margin-top: 4px; width: 276px; height: 42px;">
                <div class="webix_el_box" style="width:276px; height:42px">
                    <input id="1631034732212" type="text" value="" style="width: 272px; text-align: left;">
                </div>
            </div>
            <div class="webix_view webix_control webix_el_text" view_id="password" style="border-width: 0px; margin-left: 12px; margin-top: 4px; width: 276px; height: 42px;">
                <label style="text-align:left; line-height:13px; display:block;" onclick="" for="1631034732214" class="webix_inp_top_label ">Пароль</label>
                <div class="webix_el_box" style="width:276px; height:26px">
                    <input id="1631034732214" type="password" value="" style="width: 272px; text-align: left;">
                </div>
            </div>
            <div class="webix_view webix_control webix_el_label" view_id="$label1" style="border-width: 0px; margin-left: 12px; margin-top: 4px; width: 276px; height: 35px;">
                <div class="webix_el_box" style="width:276px;height:35px;line-height:29px">
                    <div id="captcha" style="position: relative;">
                        <div class="slide-to-unlock-bg" style="width: 280px; height: 30px; background-color: rgb(232, 232, 232);">
                            <span style="line-height: 30px; font-size: 8.57143px; color: rgb(0, 0, 153);">Slide to unlock</span>
                        </div>
                        <div class="slide-to-unlock-progress" style="background-color: rgb(255, 233, 127); height: 28px;"></div>
                        <div class="slide-to-unlock-handle" style="background-color: rgb(255, 255, 255); height: 30px; line-height: 30px; width: 35px;"></div>
                    </div>
                </div>
            </div>
            <div class="webix_view webix_control webix_el_button webix_secondary webix_disabled_view" view_id="button_logon" aria-disabled="true" style="border-width: 0px; margin-left: 12px; margin-top: 4px; width: 276px; height: 30px;">
                <div class="webix_el_box webix_disabled_box webix_disabled_top_label" style="width:276px; height:30px">
                    <button type="button" class="webix_button" disabled="true">Sign In</button>
                </div>
                <div class="webix_disabled"></div>
            </div>
        </div>
    </div>
</div>

前端登录请求逻辑

webix.ajax().post("./login",'LData='+encodeURIComponent(JSON.stringify($$("myForm").getValues(), null, 0)),{
error:function(text, data, XmlHttpRequest){ alert("There is no response from the server! Refresh the page!"); },
success:function(text, data){ 
    if (data.json().R == "Err" ) { webix.message({type:"error", text:data.json().Mess, expire:10000});  
        webix.alert({title:"Error",ok:"Ok",type:"alert-error",text: data.json().Mess /*,callback:function(){...}*/});
        $$("button_logon").disable(); initSlider();
    }
    //if (data.json().R == "Ok" ) { //location.reload(); 
    if (data.json().R != "Err" ) {
        webix.storage.local.put("aut_ui_var_un", $$("username").getValue());
        webix.SaveFormData("./reload",$$("myForm").getValues(), null, null, function(){}); //webix.alert("done");
    }
}
});

已尝试的失败实现(基于Jsoup)

第一种实现

Connection.Response response = Jsoup
                .connect("https://ams.rusoil.net/oau/login?typelogin=1&username=myuser&password=mypass")
                .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36")
                .method(Connection.Method.POST)
                .execute();
doc = Jsoup
                .connect("https://ams.rusoil.net/pcs/")
                //.cookies(response.cookies())
                .get();
System.out.println(doc.toString());

第二种实现

Connection.Response response = Jsoup
                .connect("https://ams.rusoil.net/oau/login")
                .data("username", "myuser")
                .data("password", "mypass")
                .data("typelogin", "1")
                .method(Connection.Method.POST)
                .execute();

第三种实现

Document doc = Jsoup
            .connect("https://ams.rusoil.net/oau/authorize?response_type=code&client_id=pcs_cli_serv772&redirect_uri=https%3A%2F%2Fams.rusoil.net%2Fpcs%2Froute_oau_resp&state%3D=4vcdopkaq4eh78a4mj1qvqluk2&scope=email+profile")
            .data("typelogin", "1")
            .data("username", "myuser")
            .data("password", "mypass")
            .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36")
            .cookies(response.cookies())
            .post();

解决思路

  • 修正请求参数格式:根据前端逻辑,登录请求不会直接提交username、password等单独参数,而是将表单所有值序列化为JSON字符串后,以LData为Key编码后提交。需要先构造包含typelogin、username、password以及滑块验证参数的JSON对象,序列化后作为LData参数的值提交。
  • 补充滑块校验参数:登录按钮默认处于禁用状态,只有滑动解锁完成后才会启用,同时表单会新增滑块验证通过的对应参数,未携带该参数的请求会直接被后台拦截。
  • 完善请求流程:先GET请求登录页面,获取会话Cookie以及表单所需的隐藏参数,再携带Cookie发送登录POST请求,不要跳过会话初始化步骤。
  • 补全请求头配置:添加与浏览器一致的Content-Type: application/x-www-form-urlencoded请求头,Jsoup请求需配置.ignoreContentType(true)来适配JSON格式的响应结果,避免解析报错。
  • 适配OAuth2授权流程:当前站点使用OAuth2授权机制,登录成功后需要处理302跳转,拿到授权code后访问回调地址,完成授权流程后才能访问业务页面。

内容的提问来源于stack exchange,提问作者IT_TI953

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 20:57:04