I have a list of records and need to send to the server via POST, use Retrofit 2.0 to make the requisitions. I get to make all the requests, but I'm not able to send the list.
My interface:
private interface SalesService{
@POST(API_BASE + "/registrar")
Call<List<Registro>> sendRegisters(@Body List<Registro> list);
}
Log request method:
public void senRegisters(List<Registro> registros) throws IOException {
SalesService service = requestApi.create(SalesService.class);
Call call = service.sendRegisters(registros);
call.execute().body();
}
I'm running the sendRegister () method on an IntentService.
The server side was created using PHP Slim Framework. The method I received the request is:
$app->group('/api/escolas', function() use ($app){
//recebe registros das turma e salva no banco de dados
$app->post('/registrar', function() use ($app){
$request = $app->request;
$registros = json_decode($request->getBody());
foreach($registros as $reg){
$class = $reg->turma;
$count = $reg->qtdAlunos;
$app->db->insertRegister($count, $class);
}
exit;
});
});
Can anyone help me with this?