Note that there are some explanatory texts on larger screens.

plurals
  1. POGet the final URL of a redirected request with unconventional scheme
    primarykey
    data
    text
    <p>My code (below) tries to get the final URL returned from a server that does a bit of redirecting. It works fine as long as the URLs have an http scheme. My problem arises when I want to return a URL with a different scheme. Ultimately I want, in some situations, to return a market:// url or other app launch schemes since this is for Android and I want to start Intents with them. </p> <p>So this gets me as far as retrieving the final http url, but when the final url is market:// it throws the exception seen (java.lang.IllegalStateException: Scheme 'market' not registered), and then getURI doesn't provide that one, it'll provide whatever was before that. </p> <pre><code> DefaultHttpClient client = new DefaultHttpClient(); HttpContext httpContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(mInitialUrl); try { client.execute(httpGet, httpContext); } catch (IllegalStateException e) { e.printStackTrace(); } // Parse out the final uri. HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); HttpUriRequest req = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST); return (req.getURI().isAbsolute()) ? req.getURI().toString() : (currentHost.toURI() + req.getURI()); </code></pre> <p>Now, I could just register market:// as a scheme, but I don't want to hard-code beforehand what the valid schemes are, I just want it to accept them and return them whatever they are.</p> <p>Any ideas? Maybe I'm not even taking the right approach. (Changing the server behavior isn't an option in this case... I've got to just deal with the redirects.) </p> <p>My hope is that someone can tell me how to get the HttpClient to ignore the scheme, or at least preserve the final URI it tries to access. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload