我一直在尝试从我在url字符串中指定的页面中捕获响应cookie,但是我只能获取csrftoken,因为sessionid结果为null。我现在真的不知道。我正在使用jsoup 1.8.3
public class asynctask extends AsyncTask<Void, Void, Void > {
Intent rec = getIntent();
String password = rec.getExtras().getString("logdatap");
String username = rec.getExtras().getString("logdatau");
String csrftoken, sessionid, title, title1, cookies;
Boolean psws;
String url = "https://grassi-lc-sito.registroelettronico.com/login/";
String urll = "https://grassi-lc-sito.registroelettronico.com/news";
@Override
protected Void doInBackground(Void... params) {
try {
Connection.Response loginForm = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0")
.method(Connection.Method.POST)
.execute();
Connection.Response cookies = Jsoup
.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0")
.data("username", "536763")
.data("password", "499153")
.data("btnLogin", "Log in")
.method(Connection.Method.POST)
.execute();
Document doc = cookies.parse();
sessionid = cookies.cookie("sessionid");
csrftoken = cookies.cookie("csrftoken");
Connection.Response logtest = Jsoup
.connect(urll)
.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0")
.cookie("sessionid", sessionid)
.cookie("csrftoken", csrftoken)
.method(Connection.Method.GET)
.execute();
Document paglog = logtest.parse();
}catch (IOException e) {
e.printStackTrace();}
return null;
}
@Override
protected void onPostExecute(Void result) {
Toast.makeText(getApplicationContext(), sessionid, Toast.LENGTH_SHORT).show();
if (psws){
Toast.makeText(getApplicationContext(), "nome utente errato", Toast.LENGTH_SHORT).show();
}
else {Toast.makeText(getApplicationContext(), "nome utente giusto", Toast.LENGTH_SHORT).show();}