Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:13:38+00:00 2026-05-18T08:13:38+00:00

Here is my code: DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url);

  • 0

Here is my code:

DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);

This works for every url I have tried so far, except for some urls that contain an anchor. Some of these anchored urls return a 400. The weird thing is that it isn’t all links that contain an anchor, a lot of them work just fine.

Unfortunately, I have to be really general as I can’t provide the specific urls here.

The links are completely valid and work just fine in any browser, but the HttpClient returns a 400 when trying the link. If I remove the anchor it will work.

Any ideas what to look for?

For example: http://www.somedomain.com/somedirectory/somepage#someanchor

Sorry again for the generics

EDIT: I should mention this is for Android.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:13:38+00:00Added an answer on May 18, 2026 at 8:13 am

    As @Greg Sansom says, the URL should not be sent with an anchor / fragment. The fragment part of the URL is not relevant to the server.

    Here’s the expected URL syntax from relevant part of the HTTP 1.1 specification:

        http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] 
    

    Note: there is no fragment part in the syntax.

    What happens if you do send a fragment clearly is server implementation specific. I expect that you will see a variety of responses:

    • Some servers will silently strip / ignore the fragment part. (This is what you are expecting to happen).
    • Some servers might treat this as a request error and respond with a 400.
    • Some servers might mistakenly treat the fragment as part of the path or query, and give you a 404 or some other response, depending on how “confused” the fragment makes the server.
    • Some servers might actually imbue the fragment with a specific meaning. (This strikes me as a stupid thing to do, but you never know …)

    IMO, the most sensible solution is to strip it from the URL before instantiating the HttpGet object.

    FOLLOWUP

    The recommended way to remove a fragment from a URL string is to turn it into a java.net.URL or java.net.URI instance, extract the relevant components, use these to create a new java.net.URL or java.net.URI instance (leaving out the fragment of course), and finally turn it back into a String.

    But I think that the following should also work, if you can safely assume that your URLs are all valid absolute HTTP or HTTPS URLs.

        int pos = url.indexOf("#");
        String strippedUrl = (pos >= 0) ? url.substring(0, pos) : url;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following line of code throws an Exception: HttpResponse response = client.execute(request); // actual
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
I have this code here, which is intended to allow any type of arguments:
Ok the error is showing up somewhere in this here code if($error==false) { $query
enter code here I have a table on SQL server 2005 with bigint primary
enter code here Hi All, I have a simple windows service application that connects
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
The code here is X++. I know very little about it, though I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.