2016-01-15 90 views
-1

我正在創建登錄和註冊頁面,'m正在面臨問題,json結果取零值...我檢查了fulll代碼,但是在此htpclient ,是的HttpParams有重拳出擊線對他們請修復已棄用Httpclient,httpResponse在android studio 1.5.1中被拒絕

private class AsyncDataClass extends AsyncTask<String, Void, String > { 

     @Override 

     protected String doInBackground(String... params) { 

      HttpParams httpParameters = new BasicHttpParams(); 

      HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); 

      HttpConnectionParams.setSoTimeout(httpParameters, 5000); 

      HttpClient httpClient = new DefaultHttpClient(httpParameters); 

      HttpPost httpPost = new HttpPost(params[0]); 

      String jsonResult = ""; 

      try { 

       List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 

       nameValuePairs.add(new BasicNameValuePair("name", params[1])); 

       nameValuePairs.add(new BasicNameValuePair("phoneno", params[2])); 

       nameValuePairs.add(new BasicNameValuePair("emailid", params[3])); 

       nameValuePairs.add(new BasicNameValuePair("password", params[4])); 

       httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

       HttpResponse response = httpClient.execute(httpPost); 

       jsonResult = inputStreamToString(response.getEntity().getContent()).toString(); 

       System.out.println("Returned Json object " + jsonResult.toString()); 

      } catch (ClientProtocolException e) { 

       e.printStackTrace(); 

      } catch (IOException e) { 

       e.printStackTrace(); 

      } 

      return jsonResult; 

回答

0

這是適用的:HTTP Client removed from SDK 23

這裏是我的構建腳本來解決此問題:

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 

    /* Apache HTTP Client has been removed from SDK Version 23 and up. Workaround See: https://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client */ 
    useLibrary 'org.apache.http.legacy'