0

i had problems when getting this warning..

//import org.apache.http.impl.client.DefaultHttpClient
'import org.apache.http.params.BasicHttpParams' is deprecated   
'import org.apache.http.params.HttpConnectionParams' is deprecated  
'import org.apache.http.params.HttpParams' is deprecated
import org.apache.http.protocol.HTTP 
import org.json.JSONArray    
import org.json.JSONException    
import org.json.JSONObject     

//import org.apache.http.impl.client.CloseableHttpClient   
import org.apache.http.impl.client.HttpClientBuilder    
//import java.io.IOException      

function (timeout code based on this answer by kuester2000)

try { 
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    //HttpClient httpclient = new DefaultHttpClient(); 
    HttpClient httpclient =HttpClientBuilder.create().build();
                    try{
                    HttpPost httppost = new HttpPost("http://10.0.2.2/hari.php");
                
                    StringEntity se = new StringEntity("envelope",HTTP.UTF_8);
                    httppost.setEntity(se); 
                    HttpParams httpParameters = new BasicHttpParams();
                    // Set the timeout in milliseconds until a connection is established.
                    int timeoutConnection = 3000;
                    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
                    // Set the default socket timeout (SO_TIMEOUT) 
                    // in milliseconds which is the timeout for waiting for data.
                    int timeoutSocket = 3000;
                    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); 
                    
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent(); 
                    }
                    catch(Exception e){
                        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
                    }

i am using android 5.1.1(API22)..what should i do when i got this warning error deprecated?anyone can help me?thanks in advance.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
nan
  • 1
  • 3
  • Possible Duplicate https://stackoverflow.com/questions/30556605/org-apache-http-httpentity-is-deprecated-how-to-solve-this-error-in-android-s – Sunil Soni Jan 05 '18 at 07:17
  • don't use deprecated material. there's a reason it's deprecated – Stultuske Jan 05 '18 at 07:19
  • is there any suggestion to maintain the code without change it?means its there any backward compatibility??i had try use appcompat-v7 but nothing change..the deprecated still there. – nan Jan 05 '18 at 07:27

0 Answers0