giorgos.nl
giorgos.nl

Reputation: 2832

Raw body request with retrofit

I'm trying to do the following request with retrofit2:

curl -X POST \
  https://myserver.com/token \
  -H 'Content-Type: application/json' \
  -d '{"param1": "1234", "param2": "5678"}'

but the server (which I don't have control on) is complaining that the param1 param is missing.

How this curl request would look like on retrofit2?

Upvotes: 0

Views: 326

Answers (1)

Jeel Vankhede
Jeel Vankhede

Reputation: 12118

In retrofit library (v2.0) for android,

you can create raw request body for your API in POST type, something like:

@POST("token")
public void yourApiName(@Body YourPOJO pojo);

YourPOJO.java

public class YourPOJO{
    // Your params here, use @Serialized name if using with Gson
    private String param1;
    private String param2;

    // Getters & setters here. 
}

Upvotes: 1

Related Questions