Create a HttpClient object directly
Closeablehttpclient httpClient = new Httpclients.createdefault ();
This code produces a 403 forbidden because there is a problem with the User-agent field and we need to set the UA field. UA is the identity of the browser identity.
User-agent is part of the HTTP protocol and is part of the header domain, and the User agent is also referred to as UA. In a more general sense, it is an identification of the type of browser you are using, the operating system and version, the type of CPU, the browser rendering engine, the browser language, the browser plugin, and so on, to access the site. The UA string is sent to the server each time the browser HTTP request occurs.
the standard format of the browser UA string is: Browser identification (operating system identity; encryption level identification; browser language) rendering engine identity version information
Solutions
We can use a builder to set up the UA field and then create the HttpClient object
httpclientbuilder builder = Httpclients.custom ();
Understand the meaning of each section against the standard format of the UA string
builder.setuseragent ("mozilla/5.0 (Windows; U Windows NT 5.1;en-us;rv:0.9.4) ");
Final Closeablehttpclient httpClient = Builder.build ();
Then use the Created object httpclient