Post swift error with alamofire

0

But once I come to ask for help from you. I'm developing an application in Swift using web service writing in java hosted at Amazon AWS.

When I try to make a registration via post the registration is not performed. The error that returns me is as follows

  FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.} 
FAILURE

registration code snippet

Alamofire.request(.POST, url, parameters: usuario, encoding: .JSON, headers: nil).responseJSON(completionHandler: { (response) in

                if response.result.isSuccess{

                    //self.geraAlerta("Sucesso", mensagem: "Cadastro realizado com Sucesso")
                 self.populaUsuario()
                 self.performSegueWithIdentifier("cadastroTelaPrincipal", sender: self)


                }else{
                    print(response.description,"<-------")
                    self.geraAlerta("Falha", mensagem: "Não foi possível completar o cadastro, tente novamente mais tarde!")
                }
                self.btnCadastrar.userInteractionEnabled = true 
                print(response.result)
                print(response.result.value)
            })

Code in web service

@POST
@Path("/inserir")
@Consumes(MediaType.APPLICATION_JSON)
public void insereUsuario(Usuario usuario) {

    if (usuario != null) {
        try {
            usuario.setFotoByte(Util.converteToByte(usuario.getFoto()));
            usuario.setDataCadastro(new Date());

            new UsuarioDAO().inseirUsuario(usuario);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

Can someone please tell me how to solve this problem?

If I try to access the url directly through the browser it returns me 405

    
asked by anonymous 03.09.2016 / 05:31

1 answer

0
 FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.} 
FAILURE

This error means you are passing your parameters wrong, your JSD (NSDictionary) is invalid.

Check how your parameter is and how you are expecting this JSON in your API. How is your "user" you are passing as a parameter? If you still have doubts, give a print (user) to analyze:)

    
16.09.2016 / 16:45