title: How to call php using retrofit in android?
body: <p>To call php (post) from android app using <code>Retrofit</code>.</p>
  
  <p>i get response from php in onResponse as success, but unable to receive json parameter.</p>
  
  <pre><code>Php url :
       http://www.example.com/projectname/login.php 
  Parameter :
  username = "mumbai"
  password = "mumbai"
  </code></pre>
  
  <p><strong>MainActivity.java</strong> </p>
  
  <pre><code>ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
          Call sosSensCall = apiService.getLogin("mumbai", "mumbai");
          sosSensCall.enqueue(new Callback() {
              @Override
              public void onResponse(Call call, Response response) {
                  Example example = (Example) response.body();
                  Log.d("sk_log","==="+example.getUserId());   
              }
              @Override
              public void onFailure(Call call, Throwable t) {
                  Log.d("sk_log", "Failed! Error = " + t.getMessage());
              }
  });
  </code></pre>
  
  <p><strong>APIClient.java</strong></p>
  
  <pre><code>import retrofit2.Retrofit;
  import retrofit2.converter.gson.GsonConverterFactory;
  
  
  public class ApiClient {
  
      public static final String BASE_URL = "http://www.example.com/";
      private static Retrofit retrofit = null;
      public static Retrofit getClient() {
          if (retrofit==null) {
              retrofit = new Retrofit.Builder()
                      .baseUrl(BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create())
                      .build();           
          }
          return retrofit;
      }
  }
  </code></pre>
  
  <p><strong>ApiInterface.java</strong></p>
  
  <pre><code>public interface ApiInterface {
     @POST("projectname/login.php")
  Call&lt;Example&gt; getLogin(@Query("username") String username, @Query("password") String password);
  }
  </code></pre>