Problem Description:
HTTP requests are made using httpclient, and a target host is requested at random for each request.
When you send an HTTP request, you typically configure the data source and set the clientpnames.default_host so that the target machine HOST and port are configured clientpnames.default_host at the time of the request. However, you cannot request clientpnames.default_host each time, because a httpclient corresponds to a clientpnames.default_host, you cannot modify the target HOST for a request.
For example:
HttpGet httpget = new HttpGet (URL);
When a request is made, HttpGet executes execute as a parameter, at which point the URL is a relative path, and httpclient will splice the Defaulthost+uri to the full request address for the request.
Look at HttpClient source code can find that the URI is a clue, in the Execute method will determine whether the URI set is an absolute or relative path, if the relative path httpclient will defaulthost+uri stitching as the full request address. If scheme is set in the URI and the URI is configured with the host, it will use the complete absolute path of the URI as the request address. The logic of judgment is as follows
public final HttpResponse Execute (httpurirequest request, HttpContext Context) throws IOException, clientprotocolexception {if (request = = null) {throw new Illegalargumentex
Ception ("Request must not being null.");
return execute (Request), request, Determinetarget; private static Httphost Determinetarget (Httpurirequest request) throws Clientprotocolexception {//A null target m
Ay be acceptable if there is a default target.
Otherwise, the null target is detected in the director.
Httphost target = null;
URI RequestUri = Request.geturi ();
if (Requesturi.isabsolute ()) {target = Uriutils.extracthost (RequestUri); if (target = = null) {throw new Clientprotocolexception ("URI does not specify a valid hos
T name: "+ RequestUri";
} return target; }
After analysis, we found a way to solve the problem, set the URI at the request, note that the build URI is configured to configure the scheme parameter to take effect.