title: Retrofit2 (Android) - How to send form-data along POST method
body: <p>*P.s: Changed references for security matters.</p>
  
  <p>I'm trying to get json from a server but it requires form-data in the body of request, like this:
  <a href="https://i.stack.imgur.com/bjhrS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bjhrS.png" alt="enter image description here"></a></p>
  
  <p>It works when tested in postman, but I just can't figure out how to do this using retrofit2.</p>
  
  <p>Beans:</p>
  
  <pre><code>public class Y {
  
  @SerializedName("id")
  private int yId;
  @SerializedName("name")
  private String yName;
  
  
  //...
  }
  
  
  public class YList {
  
  @SerializedName("ys")
  private List&lt;Y&gt; ys;
  
  //...
  }
  </code></pre>
  
  <p>The service interface is like this:</p>
  
  <pre><code>public interface YService {
  @POST("y")
  Call&lt;YList&gt; getY()
  
  public static final YService serviceY = new Retrofit.Builder()
          .baseUrl("http://example.com.br/api/x/")
          .addConverterFactory(GsonConverterFactory.create())
          .build()
          .create(YService.class);
  }
  </code></pre>
  
  <p>And REST method:</p>
  
  <pre><code>YService yService = YService.serviceY;
  
  
  
  
      yService.getY().enqueue(new Callback&lt;YList&gt;() {
          @Override
          public void onResponse(Call&lt;YList&gt; call, Response&lt;YList&gt; response) {
  
              if (response.isSuccessful()) {
                  //...
              } else {
  
                  //...
  
              }
  
          }
  
          @Override
          public void onFailure(Call&lt;YList&gt; call, Throwable t) {
  
              //...
  
          }
      });'
  </code></pre>
  
  <p>Postman JSON result:</p>
  
  <pre><code>{
  "auth": {
    "validation": true
  },
  "ys": [
  {
    "id": 1,
    "name": "#"
  }
  ]
  }
  </code></pre>