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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:44:31+00:00 2026-05-30T21:44:31+00:00

I am working to change the HTTP client in an application from Commons HTTP

  • 0

I am working to change the HTTP client in an application from Commons HTTP Client v3.x to the new HTTP Client v4.x. I searched but could not find good examples for the following scenarios– can you point me to a good tutorial/article on the new HTTP Client (something similar to the excellent Community Wiki article at SO on java.net.url)?

(1) set Cookie Policy

(2) set Http Proxy- defining host/domain as well as username/password

Currently this is done in the following manner–

Credentials credentials =
            ( host == null || domain == null || "".equals(host.trim()) ||     
           "".equals(domain.trim()) ) ?
                new UsernamePasswordCredentials(username, password) :
                new NTCredentials(username, password, host, domain);

 client.getState().setProxyCredentials( AuthScope.ANY, credentials);

(3) Auth credentials are defined in the old http client with the following code–

  client.getState().setCredentials(
                new AuthScope(urlObj.getHost(), urlObj.getPort()),
                new UsernamePasswordCredentials(username, password)
            );

What is the way to do this in the new HTTP client?

(4) Declaring a new HTTP Method variable and for this variable, Specifying method- as GET or POST

Code used for the above currently–

 HttpMethodBase method;
method = createPostMethod(url, params, multipart, charset);
 method = createGetMethod(url, params, charset);

(5) Adding request headers to a method –

For example, to set the user agent as Default user agent, the following code is used–

method.addRequestHeader(new Header("User-Agent", DEFAULT_USER_AGENT));
  • 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-30T21:44:32+00:00Added an answer on May 30, 2026 at 9:44 pm

    (1)cookie thing see this from another question

    (2)Proxy:

    httpclient.getCredentialsProvider().setCredentials(
                        new AuthScope("localhost", 8080),
                        new UsernamePasswordCredentials("username", "password"));
    
    HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
    HttpHost proxy = new HttpHost("localhost", 8080);
    
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    
    HttpGet httpget = new HttpGet("/");
    

    from:

    httpcomponents-client-4.1.3\examples\org\apache\http\examples\client\ClientProxyAuthentication.java

    (3)Not sure

    (4)Method

    HttpGet httpget = new HttpGet(url);
    HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" +
                        "org=self_registered_users&" +
                        "goto=/portal/dt&" +
                        "gotoOnFail=/portal/dt?error=true");
    

    From ClientFormLogin.java of example

    (5)header field:

    HttpGet get = new HttpGet(url);
    get.setHeader("Content-Type", "text/html");
    get.setHeader("User-Agent","Mozilla/4.0 (MobilePhone SCP-5500/US/1.0) NetFront/3.0 MMP/2.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
    get.setHeader("Accept-Charset", Chareset+";q=0.7,*;q=0.7");//"utf-8;q=0.7,*;q=0.7");
    get.getParams().setParameter("http.socket.timeout",20000);
    

    How about that?
    Just see the examples.

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

Sidebar

Related Questions

I am going to change my working sphere from Enterprise Web Applications written for
How can I change the current working directory from within a Java program? Everything
I'm working on using Find/Replace to change a bunch of labels to DataBound text.
I'm working with a legacy application which I'm trying to change so that it
I'm working on a legacy classic ASP interface between our client application and the
I am trying to use JSON and HTTP client to retrieve data from a
how to change the working directory of fsi in VS. how to auto load
cd is the shell command to change the working directory. How do I change
in F# interactive:how to display/change current working directory?
I decided to change a utility I'm working on to use a tabpage. When

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.