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

  • Home
  • SEARCH
  • 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 7417415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:41:53+00:00 2026-05-29T07:41:53+00:00

I am using Apache http client in java but am noticing the it refuses

  • 0

I am using Apache http client in java but am noticing the it refuses to get content on non 200 results… How do I override it?

  • 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-29T07:41:53+00:00Added an answer on May 29, 2026 at 7:41 am

    I’ve tried this:

    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.*;
    import org.apache.commons.httpclient.params.HttpMethodParams;
    
    import java.io.*;
    
    public class HttpClientTutorial {
    
      private static String url = "http://www.apache.org/";
    
      public static void main(String[] args) {
        // Create an instance of HttpClient.
        HttpClient client = new HttpClient();
    
        // Create a method instance.
        GetMethod method = new GetMethod(url);
    
        // Provide custom retry handler is necessary
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
                new DefaultHttpMethodRetryHandler(3, false));
    
        try {
          // Execute the method.
          int statusCode = client.executeMethod(method);
    
          if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + method.getStatusLine());
          }
    
          // Read the response body.
          byte[] responseBody = method.getResponseBody();
    
          // Deal with the response.
          // Use caution: ensure correct character encoding and is not binary data
          System.out.println(new String(responseBody));
    
        } catch (HttpException e) {
          System.err.println("Fatal protocol violation: " + e.getMessage());
          e.printStackTrace();
        } catch (IOException e) {
          System.err.println("Fatal transport error: " + e.getMessage());
          e.printStackTrace();
        } finally {
          // Release the connection.
          method.releaseConnection();
        }  
      }
    }
    

    on the 200 and 404 and it works as expected (error code + content). The code is from apache website itself: http://hc.apache.org/httpclient-3.x/tutorial.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a simple http client server using java. It will show
Using Apache's commons-httpclient for Java, what's the best way to add query parameters to
i am using the apache commons httpclient in a lotus notes java agent and
I am using Apache HttpClient and would like to communicate HTTP errors (400 Bad
How can I do multipart file uploads using the Apache Camel HTTP component ?
I just started using the new POI 3.6 http://poi.apache.org XSSF which was released in
I am using Apache Axis to connect my Java app to a web server.
I'm trying to automate form submission using Java to get the hours of a
I had an issue with mocking Apache Http client. The following attempt to create
I have been using various HTTP clients in java for getting various pieces of

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.