gpt4 book ai didi

javascript - 尝试在android中使用jsoup提交表单

转载 作者:搜寻专家 更新时间:2023-11-01 07:51:06 25 4
gpt4 key购买 nike

我正在尝试使用 jsoup 提交网站表单。问题是当我尝试在网络浏览器上提交表单时,会弹出一个警告框,提示您确定吗?这是它的快照

enter image description here

我试图搜索所有内容以提交弹出窗口,但找不到任何内容。

这是目前的代码

package com.example.ebad.apppw;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.util.HashMap;

public class course_registration_post extends Activity {

String url = "http://111.68.99.8/StudentProfile/RegisterCourse.aspx";
HashMap<String, String> hashMaps;

Button button;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);

hashMaps = Data.map;

button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

new course_post().execute();

}
});


}


private class course_post extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {

try
{

Connection.Response loginForm = Jsoup.connect(url).method(Connection.Method.GET).timeout(4000).execute();
Document document = loginForm.parse();


String viewstate2 = document.select("input[name=__VIEWSTATE]").attr("value");
String stategenerator2 = document.select("input[name=__VIEWSTATEGENERATOR]").attr("value");
String Eventvalidation2 = document.select("input[name=__EVENTVALIDATION]").attr("value");

Document doc = Jsoup.connect(url)
.cookies(hashMaps)
.data("__EVENTTARGET", "")
.data("__EVENTARGUMENT", "")
.data("__VIEWSTATE", viewstate2)
.data("__VIEWSTATEGENERATOR", stategenerator2)
.data("__VIEWSTATEENCRYPTED","")
.data("__EVENTVALIDATION", Eventvalidation2)
.data("ctl00$Body$COURSES_OFFERED$ctl06$cbox","on")
.data("ctl00$Body$RegisterButton", "Register Selected Courses")
.post();

/* JSContext context = new JSContext();
String script =
"function factorial(x) { var f = 1; for(; x > 1; x--) f *= x; return f; }\n" +
"var fact_a = factorial(a);\n";
context.evaluateScript(script);
*/
String s = doc.select("span[id=ctl00_MessageLabel]").text();

System.out.println(doc);


System.out.println(viewstate2);
System.out.println(stategenerator2);
System.out.println(Eventvalidation2);
System.out.println(s);


}catch (Exception e)
{
e.printStackTrace();}


return null;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}

}
}

这是我在网站上找到的警告框代码

enter image description here

我已尽一切努力使它工作,但我不知道我做错了什么。如果你们帮我解决这个问题,那将非常有帮助。

这是最终状态

__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE:ApJNDo3TJD8lI6cqluUVTLL4/+8+THmABnpE09QCLWrOcONL4Nmn1rTIUas5T69OSN7BKHF1kc+/198jt/7w+mFCczAF9MKyyAPdstjr+chGPrAI3RNKwrH+cV95bVqgAgJMq4eytLVayiyVWO2P6o6eQWy4purHq+icTc/Bbpfk7oRys7vUUpPEfOExO3eaZSD1KmIhW9IOUgcZo8Y7MVp8ysmT0l0HdAkv5a0SzT3set4MJNzD0ROwxknqRMYOdFyXeRBeatCc/CloS9TCCO6a4PJLDjFKWKZ9CP9J0AtGaIiF8z/G0oKS5Xei6lu4ZL8K4B6+nrwM5mZ2h6xG+EFBEZPOJgQF2ZzYdiwMdmXx0ANoGC/SIneIOh60syobZ2DAsx42g5EudTdinEUk09/Cem1iHm7LwXURLRexOEm38Je4q0Cou/0ncNFjlE22uO1MViXrsZo+fhJSfn0K+/HPRs8kyIUPTVcJJ7qB4KecZRBR++iEQMFuL0cpNxnMwgA6Eqc3Shq8Wp48+oHaRZtFZrXh2p+G4KJO66OdHyrF16RhPhJd0LN3xCnqoWn/RaSJmNOYZhdWpIlyG6i/umHuQ8L8LvqSJAo2BHBM3juJKoRv4Zm/SrpuGOKt1EsGOOD5YtlrO+oMz1rPtB6ddHdMazWo/KYAQryJpCg3GPDzL9182DUU1ItZ6KNw0U3jfAzjhcC8mMqYBR/6FrToECsHFDRGSfDTZqHJEbIoSTsgDIfKqCr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owipgwqFBfgYg4AqWSpj5am6fTBhj2OXchKiy4brZH4jYG49v5IS0iiWAtWJ1uT6tFmKwgzZPOXvdlkirRd/bWfw6T3/Uf4YkAlE5exxEkJAw3fx+Pabn2UNziUx58H8Hn3Df2g2TuR20iMymXq9yo8Hh3+4t96qa1BrL/DHBFH85/rTlp/NKwSwdvipLDNrUJWiHDQg2moXqC4dl/iw4cdfFXRXMfuSo1oOSbaSpZqlCFK9nQOCMFPABJTV+Gc3K3HhbE0WG5/NNgdyS2HVZDX9SQFjZ179xbduRVtL7lwqNbTCSVXP6j8FTc2JGolb0VX20IcR3Pg2L/OKUHFMW+u0LJG6Rxg==
__VIEWSTATEGENERATOR:1DA4211B
__VIEWSTATEENCRYPTED:
__EVENTVALIDATION:pVf4rtzUJV4wgdQx/akYk0gxfIjNV+uFZAXDbdglqD/e0WVKNzmOUJrcnI5ociekKl8I5T/ZeU8rhR6Slwemijo0RNWkupRo9ivsh0RC3WejftUnjRNbdBlqkS9g/jislasihd9ZJyKZLDmv0/chcscVIkgzGH/hW3cyHKZq83KkzdScHM5UWl7h87zcx7IA5DotWkh2vjEcMb6GjRUnl5R0I4ApoRUF4grYDM6lQOESzEMpW1FfS5n1aHzb49K69tesaRDRDrP0vSvpT7Hj/j40B+ectL0jpEUaiX8+fs88TKCzjGgqle/HYZudVz/Xle5nE5HZ+eX5tJE9RZYIjeZiwd/tThAJjRX/m2SE3Glql1uAIwpkb2zamffYRTZ5umLeHJk31ilK35x9D6nc9fdoatupTrHaPdUTbf4j+tnTpcTao1DEW9l536TQ9dZRDb6cMK6t7Kd5XTz8WX2UbfIvgnAIeqVod2XZqBKAHHDJoEyvDPQqLsOZ4Dh/14Jd
ctl00$Body$RegisterButton:Register Selected Courses

enter image description here

enter image description here

最佳答案

试试这个

Connection.Response loginForm = Jsoup
.connect("http://111.68.99.8/StudentProfile/")
.method(Connection.Method.GET)
.userAgent(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.0 Safari/537.36")
.execute();

Document loginDoc = loginForm.parse();
String viewstate2 = loginDoc.select("input[name=__VIEWSTATE]").attr(
"value");
String stategenerator2 = loginDoc.select(
"input[name=__VIEWSTATEGENERATOR]").attr("value");
String Eventvalidation2 = loginDoc.select(
"input[name=__EVENTVALIDATION]").attr("value");

Document document = Jsoup
..userAgent(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.0 Safari/537.36")
.connect("http://111.68.99.8/StudentProfile/RegisterCourse.aspx")
.data("__EVENTTARGET", "").data("__EVENTARGUMENT", "")
.data("__VIEWSTATE", viewstate2)
.data("__VIEWSTATEGENERATOR", stategenerator2)
.data("__VIEWSTATEENCRYPTED", "")
.data("__EVENTVALIDATION", Eventvalidation2)
.data("ctl00$Body$COURSES_OFFERED$ctl06$cbox", "on")
.data("ctl00$Body$RegisterButton", "Register Selected Courses")
.data("USERNAME_KEY", "USERNAME_VALUE")
.data("PASSWORD_KEY", "PASSWORD_VALUE")
.cookies(loginForm.cookies()).post();

上面代码的一些解释。

  1. 首先,您必须向登录页面http://111.68.99.8/StudentProfile/ 发出请求,以便生成一些cookie。这些 cookie loginForm.cookies() 是实际登录所必需的。
  2. 该页面包含一些其他值,这些值必须包含在第二个请求中才能使其正常工作。
  3. 您使用的是 android,因此您必须包含 userAgent,否则您将发送与移动设备相对应的数据,并且可能会被网站拒绝。
  4. 您案件的确认不会影响您。通过对您需要的值进行硬编码来完成这项工作,否则将由在幕后运行的 javascript 完成。

一般来说,确保发送所有需要的数据的唯一方法是检查开发工具的Network 选项卡并查看实际的Request headers

关于javascript - 尝试在android中使用jsoup提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com