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 8037711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:00:18+00:00 2026-06-05T03:00:18+00:00

Using Apache HttpClient 4.1.3 and trying to get the status code from an HttpGet

  • 0

Using Apache HttpClient 4.1.3 and trying to get the status code from an HttpGet:

HttpClient client = new DefaultHttpClient();
HttpGet response = new HttpGet("http://www.example.com");
ResponseHandler<String> handler = new BasicResponseHandler();
String body = client.execute(response, handler);

How do I extract the status code (202, 404, etc.) from the body? Or, if there’s another way to do this in 4.1.3, what is it?

Also, I assume a perfect/good HTTP response is an HttpStatus.SC_ACCEPTED but would like confirmation on that as well. Thanks in advance!

  • 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-06-05T03:00:19+00:00Added an answer on June 5, 2026 at 3:00 am

    EDIT:

    Try with:

    HttpResponse httpResp = client.execute(response);
    int code = httpResp.getStatusLine().getStatusCode();
    

    The HttpStatus should be 200 ( HttpStatus.SC_OK )

    (I’ve read too fast the problem!)


    Try with:

    GetMethod getMethod = new GetMethod("http://www.example.com");
    int res = client.executeMethod(getMethod);
    

    This should do the trick!

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

Sidebar

Related Questions

[using Apache Tomcat/7.0.27] It seems I only get this error ( HTTP Status 405
trying to access http://forum.worldoftanks.eu/index.php?app=members using apache HttpClient but keep getting 403. Can anyone help
I am trying to connect to a secure server using Apache Commons HttpClient 3.1
I am trying to familiarize myself with the Apache HttpClient by using Vogella's tutorial
I am using apache's common httpclient library. Is it possible to make HTTP request
I'm using Apache commons HTTPClient with Apache Axis 1.5 and I'm trying to log
I am using apache http commons 4.I have added both httpcore-4.0.1.jar and httpclient-4.0.1.jar in
I'm trying to make a simple http client server using java. It will show
I'm trying to add a referer to an http post in Apache HttpClient (httpclient-4.0-beta2).
I am trying to login to my JBoss webapp using the example code from

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.