java Android异步Http客户端获取帖子Url
我使用LoopJ - Async Http Client For Android执行一些异步post请求来登录网站。我正在使用AsynchttpRequestHandler来保持进程异步,并与Android UI线程分离
我想在请求之后获取页面URL——通常HTTP响应是200,在onSuccess方法之间有一个专业的3xx响应。我不确定如何访问页面URL
我见过各种使用同步或弃用方法的解决方案
- Getting URL after a redirect using HttpClient.Execute(HttpGet)-同步
- Obtaining URL from http response when no location header is sent-同步
- Apache HttpClient: Location of redirected URLs-已弃用
- HttpClient 4 - How to capture last redirect URL-已弃用(重定向策略)
当前代码结构
static AsyncHttpClient client = new AsyncHttpClient();
static {
client.setUserAgent(USER_AGENT);
client.setEnableRedirects(true);
}
public static void login(String user, String password) {
RequestParams params = new RequestParams();
params.put("login", user);
params.put("password", password);
client.post(LOGIN_URL, params, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
//Get Final Url Of Page
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//Handle Failure
}
});
}
有没有一个可能的解决方案,我可以轻松地与这个结构集成,同时在post请求成功后检索当前页面url
共 (0) 个答案