Using: org.apache.http
I am using the following code to download files, most of the url setup is done statically to save creating the object every time.
private static final HttpClient httpClient;
static {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpProtocolParams.setUseExpectContinue(params, false);
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
ConnManagerParams.setMaxTotalConnections(params, 100);
ConnManagerParams.setTimeout(params, 30000);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(), 80)); //TODO port and schema should be coming from the strings file
ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
httpClient = new DefaultHttpClient(manager, params);
//httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
}
I can call it using
private HttpUrlRequest(String host, int port, String path, List<NameValuePair> query, List<NameValuePair> post)
I want to caller to be able to specify the port number to the URL. But because
registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(), 80));
is specified statically, wouldn't I have to change that port number also? How can I solve this?