如何告诉 android 解析重定向到的页面的 XML 响应?
我正在尝试解析 Android 应用程序中的 XML 响应。解析技术本身不是问题,但接收 XML 的过程使得用普通方法很难做到这一点。
更详细: 我使用 apache httpclient(在 Android 中)请求一个 xhtml 网站。该网站位于 Java EE 应用程序服务器 (AS) 上。我在请求中提供了两个 GET 参数(用户名、密码)。
该网站位于 AS 上的安全区域,因此首先 AS 将我转发到登录页面。登录页面获取用户名和密码(来自 GET 参数)并自动登录。如果登录凭据有效,我将被重定向到所请求的 XHTML 页面。这是我想用 android SAX 解析器解析的网站。
但是当我尝试这样做时,我能够解析的唯一响应是登录页面,而不是页面。成功登录后我被重定向到。谁能告诉我如何指示 android apache http 客户端在自动登录过程后获取重定向页面的响应(用于稍后解析)?
I'm trying to parse an XML response within an Android app. The technique of parsing itself is not the problem, but the process of receiving the XML makes it difficult to do it the common way.
More in detail:
I request a xhtml website with the apache httpclient (in Android). The website is located on a Java EE Application Server (AS). I give two GET parameters with the request (username, password).
The website is located in a secure area on the AS, so first of all the AS forwards me to the login page. The loginpage takes the username and password (from the GET parameter) and logs me in automatically. If the login credentials are valid I'll get redirected to the requested XHTML page. This is the site I want to parse with the android SAX parser.
But when I try to do this, the only respose I'm able to parse is the login page, not the page. I'm redirected to after successfull login. Can anyone tell me how to instruct the android apache http client to take the response of the redirected page (for later parsing) after the automatical login process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
登录的用户存储在 HTTP 会话中,该会话由名为
JSESSIONID
的 cookie 标识。您需要确保在每个后续请求以及重定向时将获得的 cookie 传回。否则,服务器将认为重定向的请求未经授权,并将您再次重定向回登录页面。可以在
CookieStore 的帮助下管理获得的 cookie
您需要在 中设置您所在的HttpContext
依次需要传递每个HttpClient#execute()
调用。The logged-in user is stored in the HTTP session which is identified by a cookie with the name
JSESSIONID
. You need to ensure that you pass the obtained cookie back on every subsequent request, also on the redirects. Otherwise the server will consider the redirected request as unauthorized and redirect you once again back to the login page.Managing the obtained cookies can be done with help of the
CookieStore
which you need to set in theHttpContext
which you in turn need to pass on everyHttpClient#execute()
call.在此博客条目的帮助下找到了我的解决方案:
http://ginger-space.blogspot.com/2007 /04/httpclient-for-form-based.html
刚刚将代码更新到当前的 Apache 客户端,IT 工作正常。
Found my solution with the help of this blog entry:
http://ginger-space.blogspot.com/2007/04/httpclient-for-form-based.html
Just updated the Code to the current Apache Client andere IT worked.