How to send Lists with Retrofit 2.0 via POST

1

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?

    
asked by anonymous 29.10.2015 / 17:43

1 answer

0

I solved the problem by changing the list of List<Registro> by an array Registro []

    
30.10.2015 / 20:28