java - httppparams , basicHttpParams , httpconnectionparams , defaulthttpclient deprecated -
im deveolping anti theft application , found connection class , there deprecated things :
here deperecated lines : httppparams , basichttpparams , httpconnectionparams , defaulthttpclient how can solve ?? , here screenshot of deprecated lines :
import java.io.ioexception; import java.util.arraylist; import java.util.list; import org.apache.http.namevaluepair; import org.apache.http.client.httpclient; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.basicresponsehandler; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.message.basicnamevaluepair; import org.apache.http.params.basichttpparams; import org.apache.http.params.httpconnectionparams; import org.apache.http.params.httpparams; import org.apache.http.params.httpprotocolparams; public class httprmi { private httppost request = null; private list<namevaluepair> namevaluepairs = null; private int connectiontimeoutmillis = 300*1000; private int sockettimeoutmillis = 0; private httpclient httpclient; public httprmi(string url){ request = new httppost(url); namevaluepairs = new arraylist<namevaluepair>(1); httpparams httpparams = new basichttpparams(); httpconnectionparams.setconnectiontimeout(httpparams, connectiontimeoutmillis); httpconnectionparams.setsotimeout(httpparams, sockettimeoutmillis); httpprotocolparams.setcontentcharset(httpparams, "utf-8"); httpclient = new defaulthttpclient(httpparams); } public httprmi add(string key, string value){ namevaluepairs.add(new basicnamevaluepair(key, value)); return this; } public string execute() throws ioexception{ string response = ""; try{ request.setentity(new urlencodedformentity(namevaluepairs, "utf-8" ) ); response = httpclient.execute(request, new basicresponsehandler()); }catch(exception e){ e.printstacktrace(); throw new ioexception("no connection"); } return response; }
}
the best alternatives httpclient
using okhttp or httpurlconnection.
new applications should use httpurlconnection; spending our energy going forward. link
Comments
Post a Comment