Send plain text with retrofit

0
{ Cliente_ID: 1, Nombre_Usuario: "dsadsadsa"}

The problem is that the api receives plain text, try to use retrofit in the following way:

  

Interface

@POST("Cliente")
Call<Client> newClient(@Body Client client);
  

Model

@SerializedName("Cliente_ID")
@Expose
private Integer clienteID;
@SerializedName("Nombre_Usuario")
@Expose
private String nombreUsuario;
contruct.. gets.sets..

Retrofit configuration

retrofit = new Retrofit.Builder()
                    .baseUrl(baseurl)
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();

Using postman I realized that when trying to send the values at the beginning of this question as JSON (application/json) do not accept them, just accept Text (text/plain) are enough parameters that I should send, any solution to this? how do I configure retrofit to send the parameters in plain text, but in JSON format? ...

    
asked by DoubleM 19.08.2018 в 21:54
source

1 answer

1

Have you tried using RequestBody?

String text = "plain text request body";  
RequestBody body=RequestBody.create(MediaType.parse("text/plain"), text);
Call<ResponseBody> call = service.getStringRequestBody(body);  
Response<ResponseBody> response = call.execute();  
String value = response.body().string();  

You can get more information here: link

Greetings

    
answered by 20.08.2018 в 00:03