I learn to know where actually link redirect from an URL.
After testinf on redirect URL web site, it give url redirect type 301.
So, I test based on link below to get real link.
Get hold of redirect url with Java org.apache.http.client
Code looks like below:
HttpGet httpget = new HttpGet(filename);
HttpContext context = new BasicHttpContext();
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute((HttpUriRequest) httpget, context);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
throw new IOException(response.getStatusLine().toString());
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
HttpHost currentHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
String currentUrl = currentHost.toURI() + currentReq.getURI();
System.out.println(currentUrl);
but I got this message:
The method execute(HttpUriRequest, HttpContext) in the type AbstractHttpClient is not >applicable for the arguments (HttpGet, HttpContext)
Would some body help me, what’s wrong in this code?
Your code works well for me with this httpclient dependency:
and with these imports:
Check that you are using the correct dependencies.