You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2010/11/18 17:01:16 UTC
[jira] Resolved: (HTTPCLIENT-1023) Unable to get the redirect uri
from
http://local.direct.gov.uk/LDGRedirect/index.jsp?LGSL=58&LGIL=08&AgencyId=35&Type=Single
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1023?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCLIENT-1023.
-------------------------------------------
Resolution: Not A Problem
Some sites may simply have issues with HEAD requests.
Please post all your further questions to the user list. Usually a wire log of the HTTP session helps find out the cause of the problem a great deal.
Oleg
> Unable to get the redirect uri from http://local.direct.gov.uk/LDGRedirect/index.jsp?LGSL=58&LGIL=08&AgencyId=35&Type=Single
> ----------------------------------------------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-1023
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1023
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 4.0.3
> Environment: windows XP
> Reporter: Roy Silva
>
> Hi,
> I visit the above page http://local.direct.gov.uk/LDGRedirect/index.jsp?LGSL=58&LGIL=08&AgencyId=35&Type=Single. This page takes me to http://www.brent.gov.uk/revsbens.nsf/counciltax/LBB-1.
> The problem is that I can not reach the other page via a redirect. If I user another redirection site, it works but not the one above.
> I use the httphead to get the redirected url then construct an htmlget to get the data. The program stops working at HttpResponse response = httpClient.execute(httpHead, localContext);
> Please help. Thank you in advance.
> Please see my code.
> public static void main(String[] args) throws Exception {
> final HttpParams params = new BasicHttpParams();
> HttpClientParams.setRedirecting(params, false);
>
> String login = "username:password";
> String encoded = new String(Base64.encodeBase64(login.getBytes()));
> Properties systemSettings = System.getProperties();
> systemSettings.put("proxySet", "true");
> systemSettings.put("http.proxyHost", "proxy");
> systemSettings.put("http.proxyPort", "port");
> /* basic credentials for site being accessed */
> CredentialsProvider credProvider = new BasicCredentialsProvider();
> credProvider.setCredentials(new AuthScope("proxy", port),
> new UsernamePasswordCredentials("username", "password"));
> DefaultHttpClient httpClient = new DefaultHttpClient();
>
> HttpContext localContext = new BasicHttpContext();
> httpClient.setCredentialsProvider(credProvider);
> ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector
> .getDefault());
> httpClient.setRoutePlanner(routePlanner);
> //HttpHead httpHead = new HttpHead("http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGrJk-F7Dmshmtze2yhifxRsv8sRg&url=http://www.mtv.com/news/articles/1647243/20100907/story.jhtml");
> HttpHead httpHead = new
> HttpHead("http://local.direct.gov.uk/LDGRedirect/index.jsp?LGSL=58&LGIL=08&AgencyId=35&Type=Single");
> DefaultRedirectHandler redHand = new DefaultRedirectHandler();
> httpClient.setRedirectHandler(redHand);
> HttpResponse response = httpClient.execute(httpHead, localContext);
> if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
> throw new IOException(response.getStatusLine().toString());
> HttpUriRequest currentReq = (HttpUriRequest) localContext.getAttribute(
> ExecutionContext.HTTP_REQUEST);
> HttpHost currentHost = (HttpHost) localContext.getAttribute(
> ExecutionContext.HTTP_TARGET_HOST);
> String currentUrl = currentHost.toURI() + currentReq.getURI();
>
> System.out.println(">>> " +currentUrl);
>
>
>
> System.out.println("response status: " + response.getStatusLine());
> // test the target
> HttpHost target = (HttpHost) localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
> HttpUriRequest request = (HttpUriRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
> System.out.println("target is: " + target);
> System.out.println("final req: " + request.getURI());
> System.out.println("target method: " + request.getMethod());
> System.out.println("redHand: " + redHand.isRedirectRequested(response, localContext));
>
> // now construct an httpGet
> HttpGet httpGet = new HttpGet(request.getURI());
> response = httpClient.execute(httpGet, localContext);
> HttpEntity entity = response.getEntity();
> if (entity != null) {
> BufferedReader in = null;
> try {
> InputStream inputStream = entity.getContent();
> in = new BufferedReader(new InputStreamReader(inputStream));
> String inputLine;
> while ((inputLine = in.readLine()) != null) {
> System.out.println(inputLine);
> while ((inputLine = in.readLine()) != null) {
> TagStripper tagStripper = new TagStripper(inputLine);
> while (tagStripper.hasNext()) {
> String tempString = tagStripper.next();
> ContentStripper contentStripper = new ContentStripper(tempString);
> String name = contentStripper.getName();
> if (name != null) {
> if (name.length() > 0) {
> String content = contentStripper.getContent();
> System.out.println("Name: " + name + " content: " + content);
> }
> }
> }
> // System.out.println(inputLine);
> }
> }
> } catch (Exception e) {
> System.out.println("Error in communicaton: " + e.getMessage());
> }
> in.close();
> }
> httpClient.getConnectionManager().shutdown();
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org