使用JSoup将类似浏览器的XmlHTTP发布请求发送到部分渲染网站

时间:2019-06-02 10:13:16

标签: android post xmlhttprequest jsoup

我正在尝试在使用XmlHttpRequest(XHR提交表单的网站)上自动化表单填写过程。该网站似乎正在使用jsf进行部分呈现。浏览器对表单提交请求的网络检查如下:

标题:

Host: parivahan.gov.in
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0
Accept: application/xml, text/xml, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://parivahan.gov.in/rcdlstatus/vahan/rcDlHome.xhtml
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Faces-Request: partial/ajax
X-Requested-With: XMLHttpRequest
Content-Length: 2763
Connection: keep-alive
Cookie: JSESSIONID=2B3C90A71BDF441976210C3964AF3BFC; has_js=1

发布数据:

javax.faces.partial.ajax    true
javax.faces.source  form_rcdl:j_idt45
javax.faces.partial.execute @all
javax.faces.partial.render  form_rcdl:pnl_show+form_rcdl:pg_show+form_rcdl:rcdl_pnl
form_rcdl:j_idt45   form_rcdl:j_idt45
form_rcdl   form_rcdl
form_rcdl:tf_reg_no1    AB12CD
form_rcdl:tf_reg_no2    1234
form_rcdl:j_idt35:CaptchaID 4dr3k
javax.faces.ViewState   dJvaWTZ3M6T1uekahmH...

获得的响应为(请注意更新ID):

<partial-response id="j_id1">
<changes>
<update id="form_rcdl:rcdl_pnl">
<![CDATA[<div id="form_rcdl:rcdl_pnl" class="ui-panel ui-widget ui-widget-content ui-corner-all datatable-panel" data-widget="widget_form_rcdl_rcdl_pnl">
...

相应的Jsoup代码

Connection connection = Jsoup.connect("https://parivahan.gov.in/rcdlstatus/vahan/rcDlHome.xhtml")
.userAgent("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0")
.header("Accept","application/xml, text/xml, */*; q=0.01")
.header("Accept-Language","en-US,en;q=0.5")
.header("Accept-Encoding","gzip, deflate, br")
.header("Content-Type","application/x-www-form-urlencoded; charset=UTF-8")
.header("Faces-Request","partial/ajax")
.header("X-Requested-With","XMLHttpRequest")
.cookies(GetCaptcha.cookies) // cookies verified
.data("javax.faces.partial.ajax", "true")
.data("javax.faces.source", "form_rcdl:j_idt45")
.data("javax.faces.partial.execute", "@all")
.data("javax.faces.partial.render", "form_rcdl:pnl_show+form_rcdl:pg_show+form_rcdl:rcdl_pnl")
.data("form_rcdl:j_idt45", "form_rcdl:j_idt45")
.data("form_rcdl", "form_rcdl")
.data("form_rcdl:tf_reg_no1", "AB12CD")
.data("form_rcdl:tf_reg_no2", "1234")
.data("form_rcdl:j_idt32:CaptchaID", "4dr3k")
.data("javax.faces.ViewState", GetCaptcha.viewState)
.timeout(10000);

Log.d(TAG,"Sending Post request :" + connection.request().data());
Document document = connection.post();
statusCode = connection.response().statusCode();
Log.d(TAG,"Response Status code:"+statusCode);

已获得答复:

<partial-response id="j_id1">
<changes>
<update id="form_rcdl:j_idt15">
<![CDATA[<div id="form_rcdl:j_idt15" class="ui-messages ui-widget" aria-live="polite"></div>]]>
...

现在的问题是,尽管响应的状态码为200 OK,但我没有从站点获得预期的响应。我在这里想念什么?

0 个答案:

没有答案