1
嗨,每一个它已经两天了,现在我正在尝试解决我的问题。 我有url链接,我试图用AsyncHttpClient类调用,我需要等待链接所做的重定向。问题在于http get请求返回一个http响应200和http内容而不等待重定向。请问你能帮帮我吗?
下面是代码:
Java非常等待http重定向
private static String getAsyncRedirectedUrlFromUrl(String url) {
AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
Future<Response> response = asyncHttpClient.prepareGet(url).execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
// Do something with the Response
// ...
response.getLocalAddress();
response.getStatusCode();
return response;
}
@Override
public void onThrowable(Throwable t) {
// Something wrong happened.
}
});
try {
System.out.println("Redirection:" + response.get().getHeader("location"));
return response.get().getHeader("location");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
这里是请求链接:Request LINK
这里是预期结果重定向链接:Expect LINK
感谢你的帮助,它会非常有帮助。
感谢您的帮助:-),我已经能够解决与Selenium的问题。 – Mehdi