java - Set HttpParams object in HttpClient 4.0 -


i creating new httpclient, passing threadsafeclientconnmanager , httpparams in it's constructor, throws bad request error. figure out went wrong had debugged in vain. provide me solution here code block

sc.register(new scheme("http", plainsocketfactory.getsocketfactory(), 80)); sc.register(new scheme("https", sslsocketfactory.getsocketfactory(), 443));  httpparams basicparams = new basichttpparams(); threadsafeclientconnmanager connmgr = new threadsafeclientconnmanager(basicparams, sc); connmanagerparams.setmaxconnectionsperroute(     basicparams,     // if have more 5 concurrent leads, problem have     new connperroute() {         public int getmaxforroute(httproute httproute) {         return 5;     } });   g_client = new defaulthttpclient(connmgr, basicparams);  // it's lead, forgiving timeout g_client.getparams().setparameter(coreconnectionpnames.connection_timeout, 5000); g_client.getparams().setparameter(coreconnectionpnames.so_timeout, 5000); connmanagerparams.settimeout(basicparams, 2000); 

when call g_client.execute(postmethod); in code shows 400 status code means wrong request. if pass null in defaulthttpclient constructor

g_client = new defaulthttpclient(connmgr, null); 

the client executing successfully, it's not right way need basic param set maxconnectionperroute. had paste here doubtful code. please have , me. stuck here.

i using httpclient 4.0 version.

in 1 of our older projects trying except set default max connections per route directly on setdefaultmaxperroute(int) method in threadsafeclientconnmanager (without need setting params in way do).

also, believe connmanagerparams.settimeout(basicparams, 2000) equivalent (and can replaced with) g_client.getparams().setparameter(connmanagerpnames.timeout, 2000);.

example alternative code:

schemeregistry sc = new schemeregistry(); sc.register(new scheme("http", 80, plainsocketfactory.getsocketfactory())); sc.register(new scheme("https", 443, sslsocketfactory.getsocketfactory()));  threadsafeclientconnmanager connmgr = new threadsafeclientconnmanager(sc); connmgr.setdefaultmaxperroute(5);  /// alternative approach yours ///  defaulthttpclient g_client = new defaulthttpclient(connmgr); g_client.getparams().setparameter(coreconnectionpnames.connection_timeout, 5000); g_client.getparams().setparameter(coreconnectionpnames.so_timeout, 5000); g_client.getparams().setparameter(connmanagerpnames.timeout, 2000);   /// alternative approach yours /// 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -