title: Retrofit POST: JSON object does't send to PHP server
body: <p>I'm trying to send an object of <code>User</code> class (using Gson-Retrofit) to server via <code>POST</code> method from Android. If server receive any data, it will send a JSON object to App which contains KEY &quot;success&quot; and &quot;message&quot;. But unfortunately each and every time server sends <strong>{&quot;success&quot;:false,&quot;message&quot;:&quot;No&quot;}</strong> to App.</p>
  <p>I think there are something wrong when I call the method from MainActivity. For more understanding all of my codes are given below:</p>
  <h3>From <code>MainActivity.java</code> I call this method:</h3>
  <pre><code>    private void checkUserValidity(User userCredential){
  
      ApiInterface apiInterface = RetrofitApiClient.getClient().create(ApiInterface.class);
      Call&lt;ValidityResponse&gt; call = apiInterface.getUserValidity(userCredential);
  
      call.enqueue(new Callback&lt;ValidityResponse&gt;() {
  
          @Override
          public void onResponse(Call&lt;ValidityResponse&gt; call, Response&lt;ValidityResponse&gt; response) {
  
              ValidityResponse validity = response.body();
              Toast.makeText(getApplicationContext(), validity.getMessage(), Toast.LENGTH_LONG).show();
          }
  
          @Override
          public void onFailure(Call call, Throwable t) {
              Log.e(TAG, t.toString());
          }
      });
  }
  </code></pre>
  <p><strong>My <code>ApiInterface.java</code> class is:</strong></p>
  <pre><code>public interface ApiInterface {
      @POST(&quot;/retrofit_login/login.php&quot;)
      Call&lt;ValidityResponse&gt; getUserValidity(
          @Body User userLoginCredential);
  }
          
  </code></pre>
  <p><strong><code>RetrofitApiClient.java</code> class is:</strong></p>
  <pre><code>public class RetrofitApiClient {
  
          private static final String BASE_URL = &quot;http://192.168.0.101&quot;; //address of your localhost
          private static Retrofit retrofit = null;
  
          private static Gson gson = new GsonBuilder()
                  .setLenient()
                  .create();
  
          public static Retrofit getClient() {
              if (retrofit==null) {
                  retrofit = new Retrofit.Builder()
                          .baseUrl(BASE_URL)
                          .addConverterFactory(GsonConverterFactory.create(gson))
                          .build();
              }
              return retrofit;
          }
      }
  </code></pre>
  <p><strong><code>User.java</code> class is:</strong></p>
  <pre><code>public class User {
  
      @SerializedName(&quot;user_id&quot;)
      private String userId;
      @SerializedName(&quot;password&quot;)
      private String password;
  
      public User(){}
  
      public void setUserId(String userId) {
          this.userId = userId;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  }
  </code></pre>
  <p><strong><code>ValidityResponse.java</code> class is:</strong></p>
  <pre><code>public class ValidityResponse {
  
      @SerializedName(&quot;success&quot;)
      boolean successString;
      @SerializedName(&quot;message&quot;)
      String messageString;
  
      public boolean isSuccess(){
          return successString;
      }
  
      public String getMessage() {
          return messageString;
      }
  }
  </code></pre>
  <p><strong>And finally the server side php code is:</strong></p>
  <pre><code>&lt;?php
  
      if (isset($_POST['user_id']) &amp;&amp; isset($_POST['password']))
          $json =  array('success' =&gt; true, 'message' =&gt; 'Yes');
      else
          $json =  array('success' =&gt; false, 'message' =&gt; 'No');
      
      echo json_encode($json);
  ?&gt;
  </code></pre>
  <p>Where is the problem? What should I do now?
  Thanks for your time.</p>