title: HttpClient deprecated / Connect with PHP server - Android API 22
body: <p>I am trying to make a login and register for an android app.
  I have been having problems adjusting the code to API 22.
  Although I know I have to use <code>HttpURLConnection</code> instead of <code>HttpRequestParams</code> etc., and have done that, I can't figure out how to adjust the code to incorporate the database server and my PHP files stored on there.</p>
  
  <p>It's mostly this bit below that I can't figure out.</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient(httpRequestParams);
  HttpPost post = new HttpPost(SERVER_ADDRESS + "FetchUserData.php");
  </code></pre>
  
  <p>Can anyone help? Thanks in advance.</p>
  
  <p>Here's the full code:</p>
  
  <pre><code>        @Override
          protected User doInBackground(Void... params) {
  
              ContentValues contentValues = new ContentValues();
              contentValues.put("username", user.username);
              contentValues.put("password", user.password);
  
              URL url = new URL(SERVER_ADDRESS);
              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.setConnectTimeout(CONNECTION_TIMEOUT);
              conn.setReadTimeout(CONNECTION_TIMEOUT);
  
              HttpClient client = new DefaultHttpClient(httpRequestParams);
              HttpPost post = new HttpPost(SERVER_ADDRESS + "FetchUserData.php");
  
              User returnedUser = null;
              try {
                  post.setEntity(new UrlEncodedFormEntity(dataToSend));
                  HttpResponse httpResponse = client.execute(post);
  
                  HttpEntity entity = httpResponse.getEntity();
                  String result = EntityUtils.toString(entity);
                  JSONObject jObject = new JSONObject(result);
  
                  if(jObject.length() == 0) {
                      returnedUser = null;
                  } else {
                      String mobile = jObject.getString("mobile");
                      String email = jObject.getString("email");
  
                      returnedUser = new User(mobile, email, user.mobile, user.email);
                  }
  
              } catch(Exception e) {
                  e.printStackTrace();
              }
  
              return returnedUser;
          }
  </code></pre>