无法使用Android身份验证数据访问中的JSoup库获得预期输出

时间:2017-12-11 19:54:06

标签: java android jsoup

我尝试了很多解决方案,但它对我无效。请帮助我,我将传递JSoup中的所有数据和标题,而且我还没有在http://webproject.live/php/demo/post.php中收到成功登录的消息 但是当我尝试从浏览器登录时,它将完美运行。 http://webproject.live/php/demo/

enter image description here

代码: -

public class MainActivity extends AppCompatActivity {

    private ProgressDialog mProgressDialog;
    private String text;

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

        new Description().execute();

    }

    private class Description extends AsyncTask<Void, Void, Void> {
        String desc;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                // Connect to the web site
                Document page = Jsoup
                        .connect("http://www.webproject.live/php/demo/post.php")
                        .data("username", "yudiz")
                        .data("password", "yudiz@123")
                        .header("Origin","http://webproject.live")
                        .header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\n")
                        .header("Accept-Encoding","gzip, deflate")
                        .header("Accept-Language","en-GB,en-US;q=0.9,en;q=0.8")
                        .header("Cache-Control","max-age=0")
                        .header("Connection","keep-alive")
                        .header("Content-Type","application/x-www-form-urlencoded")
                        .header("Host","webproject.live")
                        .header("Referer","http://webproject.live/php/demo")
                        .header("Upgrade-Insecure-Requests","1")
                        .post();

                text = page.text();

                Log.i("TAG1 Page",page.toString());

            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            // Set description into TextView

            TextView tv_title = (TextView) findViewById(R.id.tv_text);
            tv_title.setText(text);
        }
    }

}

0 个答案:

没有答案