title: Retrofit POST method returns error 400
body: <p>I would like to call a POST Method(Django REST framework) in Retrofit with a  For that, I call as follow from the postman and works fine for me.</p>
  
  <p><a href="https://i.stack.imgur.com/kd3YY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kd3YY.png" alt="postman"></a>
  I have done the Android part as follows:</p>
  
  <p>API INTERFACES:</p>
  
  <pre><code>public interface SOService {
  
     @FormUrlEncoded
  @POST("/api-auth/")
  Call&lt;Tokken&gt; get_tokken(@Field("username") String username, @Field("password") String password);
  
  }
  </code></pre>
  
  <p>APIUtility class as</p>
  
  <pre><code>public class ApiUtils {
  
      public static final String BASE_URL = "http://10.0.2.2:8000/";
  
      public static SOService getSOService() {
          return RetrofitClient.getClient(BASE_URL).create(SOService.class);
      }
  }
  </code></pre>
  
  <p>RetrofitClient as :</p>
  
  <pre><code>public class RetrofitClient {
  
      private static Retrofit retrofit = null;
  
      public static Retrofit getClient(String baseUrl) {
  
          OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
  
  
  
          if (retrofit==null) {
  
  
              retrofit = new Retrofit.Builder()
              .baseUrl(baseUrl)
              .client(clientBuilder.build())
              .addConverterFactory(GsonConverterFactory.create())
              .build();
          }
          return retrofit;
      }
  }
  </code></pre>
  
  <p>And finally, call the function as following</p>
  
  <pre><code>private void signIn() {
      boolean isValid = validate();
      if (isValid) {
  
          mService.get_tokken(user.getText().toString(), password.getText().toString()).enqueue(new Callback&lt;Tokken&gt;() {
              @Override
              public void onResponse(Call&lt;Tokken&gt; call, Response&lt;Tokken&gt; response) {
                  if (response.isSuccessful()) {
  
                      System.out.println("Te lo imprimo");
                      System.out.println(response.body().toString());
                      Toast.makeText(LoginActivity.this, "tokken recibido", Toast.LENGTH_SHORT).show();
                  } else {
                      int statusCode = response.code();
                      // handle request errors depending on status code
                  }
              }
  
              @Override
              public void onFailure(Call&lt;Tokken&gt; call, Throwable t) {
                  Toast.makeText(LoginActivity.this, "Error al recibir tokken", Toast.LENGTH_SHORT).show();
  
                  t.printStackTrace();
                  Log.d("MainActivity", "error loading from API");
  
              }
          });
          /*startActivity(new Intent(this, RolSelection.class));*/
      }
  }
  </code></pre>
  
  <p>And the final result is always the same, I get this message in the server:</p>
  
  <blockquote>
    <p>[17/Apr/2018 01:12:33] "POST /api-auth/ HTTP/1.1" 200 52</p>
  </blockquote>
  
  <p>But in Android  I get this:</p>
  
  <blockquote>
    <p>I/System.out: Te lo imprimo
                  Tokken{tokken='null'}</p>
  </blockquote>
  
  <p>Any idea why the tokken is null? When I use postman I get a result.</p>
  
  <p>UPDATE with the Tokken class:</p>
  
  <pre><code>public class Tokken {
  
      @SerializedName("tokken")
      @Expose
      private String tokken;
  
      public String getTokken() {
          return tokken;
      }
  
      public void setTokken(String tokken) {
          this.tokken = tokken;
      }
  
      @Override
      public String toString() {
          return "Tokken{" +
                  "tokken='" + tokken + '\'' +
                  '}';
      }
  }
  </code></pre>