简体   繁体   English

Android-获取需要登录的页面的源代码

[英]Android - Get source code of a page that needs login

I'm trying to get the source code of a page that needs user login. 我正在尝试获取需要用户登录的页面的源代码。

I need this to make an android application. 我需要这个来制作一个android应用程序。 I already tryed jsoup with POST session cookie and then GET but that ends in an force close. 我已经尝试过用POST会话cookie和GET进行jsoup了,但是以强制关闭而告终。 I also tryed DefaultHttpClient and that ends in that i'm not logged in. The login works but when I want to load the profile page it brings me back to the login page. 我还尝试了DefaultHttpClient,结果以未登录为准。登录有效,但是当我要加载配置文件页面时,它将带我回到登录页面。 The login is lost and I don't know why. 登录丢失,我不知道为什么。 When I use DefaultHttpClient and stays in the same client and then do a post it gives me an error on console that the connection needs to be close before request a new page. 当我使用DefaultHttpClient并停留在同一客户端中,然后执行发布时,它在控制台上给我一个错误,要求关闭连接才能请求新页面。

What I need is this. 我需要的是这个。 Login on page http://www.example.com/login then I need the source code of the page that is like http://www.example.com/profile 在页面http://www.example.com/login上登录,然后我需要该页面的源代码,例如http://www.example.com/profile

When you logged in on the website you will be redirect to example.com when it fails you will go again to the login page. 当您登录网站时,如果失败,您将被重定向到example.com,您将再次进入登录页面。

What do I need to do to let it work on Android, not in Java i've already done it in java but that code fails in an Android app becouse it won't holds it's cookies 我需要做些什么才能使其在Android上工作,而不是在Java中工作,我已经在Java中完成了工作,但是该代码在Android应用程序中失败了,因为它无法保存Cookie

I'm programming it for android 2.3.3 and higher. 我正在为Android 2.3.3及更高版本进行编程。

With DefaultHttpClient, you'll need to set the cookie store if you want to hold on to the session token for your request to the profile page. 使用DefaultHttpClient,如果要保留会话令牌以访问个人资料页面,则需要设置cookie存储。

    DefaultHttpClient httpClient = new DefaultHttpClient();
    CookieStore cookieJar = new BasicCookieStore();
    httpClient.setCookieStore(cookieJar);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM