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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:03:36+00:00 2026-05-11T18:03:36+00:00

I’m doing a Get and Post method for an android project and I need

  • 0

I’m doing a Get and Post method for an android project and I need to “translate” HttpClient 3.x to HttpClient 4.x (using by android).
My problem is that I’m not sure of what I have done and I don’t find the “translation” of some methods…

This is the HttpClient 3.x I have done and (–>) the HttpClient 4.x “translation” if I have found it (Only parties who ask me problems) :

HttpState state = new HttpState (); --> ?

HttpMethod method = null; --> HttpUriRequest httpUri = null;

method.abort(); --> httpUri.abort(); //httpUri is a HttpUriRequest

method.releaseConnection(); --> conn.disconnect(); //conn is a HttpURLConnection

state.clearCookies(); --> cookieStore.clear(); //cookieStore is a BasicCookieStore

HttpClient client = new HttpClient(); --> DefaultHttpClient client = new DefaultHttpClient();

client.getHttpConnectionManager().getParams().setConnectionTimeout(SOCKET_TIMEOUT) --> HttpConnectionParams.setConnectionTimeout(param, SOCKET_TIMEOUT);

client.setState(state); --> ?

client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); --> HttpClientParams.setCookiePolicy(param, CookiePolicy.RFC_2109);

PostMethod post = (PostMethod) method; --> ?

post.setRequestHeader(...,...); --> conn.setRequestProperty(...,...);

post.setFollowRedirects(false); --> conn.setFollowRedirects(false);

RequestEntity tmp = null; --> ?

tmp = new StringRequestEntity(...,...,...); --> ?

int statusCode = client.executeMethod(post); --> ?

String ret = method.getResponsBodyAsString(); --> ?

Header locationHeader = method.getResponseHeader(...); --> ?

ret = getPage(...,...); --> ?

I don’t know if that is correct.
This has caused problems because the packages are not named similarly, and some methods too.
I just need documentation (I haven’t found) and little help.

  • 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-11T18:03:37+00:00Added an answer on May 11, 2026 at 6:03 pm

    The easiest way to answer my question is to show you the class that I made :

    public class HTTPHelp{
    
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        private boolean abort;
        private String ret;
    
        HttpResponse response = null;
        HttpPost httpPost = null;
    
        public HTTPHelp(){
    
        }
    
        public void clearCookies() {
    
            httpClient.getCookieStore().clear();
    
        }
    
        public void abort() {
    
            try {
                if(httpClient!=null){
                    System.out.println("Abort.");
                    httpPost.abort();
                    abort = true;
                }
            } catch (Exception e) {
                System.out.println("HTTPHelp : Abort Exception : "+e);
            }
        }
    
        public String postPage(String url, String data, boolean returnAddr) {
    
            ret = null;
    
            httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
    
            httpPost = new HttpPost(url);
            response = null;
    
            StringEntity tmp = null;        
    
            httpPost.setHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux " +
                "i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)");
            httpPost.setHeader("Accept", "text/html,application/xml," +
                "application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
            httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    
            try {
                tmp = new StringEntity(data,"UTF-8");
            } catch (UnsupportedEncodingException e) {
                System.out.println("HTTPHelp : UnsupportedEncodingException : "+e);
            }
    
            httpPost.setEntity(tmp);
    
            try {
                response = httpClient.execute(httpPost,localContext);
            } catch (ClientProtocolException e) {
                System.out.println("HTTPHelp : ClientProtocolException : "+e);
            } catch (IOException e) {
                System.out.println("HTTPHelp : IOException : "+e);
            } 
                    ret = response.getStatusLine().toString();
    
                    return ret;
                    }
    }
    

    I used this tutorial to do my post method and thoses examples

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

Sidebar

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer echo '<p style="color:#000;">test</p>'; or echo "<p style=\"color:#000;\">test</p>'; and a couple… May 12, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer When I tried to write a ebook library for Emacs,… May 12, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer This was a bug with ActiveScaffold that was fixed this… May 12, 2026 at 6:06 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.