对于basichttpparams,httpconnectionparams和httpparams,在eclipse中不推荐使用警告

时间:2018-01-05 07:13:35

标签: java android eclipse

我在收到此警告时遇到了问题..

//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      

功能

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();
                    }

我正在使用android 5.1.1(API22)..当我收到此警告错误时,我该怎么办?有人可以帮助我吗?提前感谢。

0 个答案:

没有答案