[英]How do i call this code using jsoup login
How do I call this code.我如何调用此代码。
public static void main(String[] args) throws Exception {
Connection.Response loginForm = Jsoup.connect("http://deeproute.com/deeproute/default.asp")
.method(Connection.Method.GET)
.execute();
Document document = Jsoup.connect("http://deeproute.com/deeproute/default.asp")
.data("cookieexists", "false")
.data("name", "username")
.data("password", "pass")
.data("subbera", "Login")
.cookies(loginForm.cookies())
.post();
}
I want to know how to call this code I have added this to my MainActivity
and now I want to know how to call it.我想知道如何调用此代码 我已将其添加到
MainActivity
,现在我想知道如何调用它。 I am learning how to make a post
using jsoup
.我正在学习如何使用
jsoup
post
。
You can't use this code directly in MainActivity
- It has a long execution time so it will block the UI which is not allowedby Android.您不能直接在
MainActivity
使用此代码 - 它的执行时间很长,因此会阻塞 Android 不允许的 UI。 Put that code in an AsyncTask
and call the task from your main.将该代码放在
AsyncTask
并从您的主调用任务。 You can use it like this:你可以这样使用它:
@Override
public void onCreate(Bundle savedInstanceState) {
//Do some stuff here
new ConnectToInternet().execute(); //And call your task
}
private class ConnectToInternet extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
//place here your code for accessing the web
return YOUR_ANSWER_AS_STRING //or modify the return type
}
@Override
protected void onPostExecute(String result) {
//This method receives your String result of
//doInBackground so you can process it here.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.