Error post in Swift with still

Asked

Viewed 71 times

0

But I once came to you for help. I’m developing a Swift application using web service written in java hosted on Amazon AWS.

When I try to register via post the registration is not carried out. The error that returns me is the following

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

excerpt from the register code

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 on the 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();
        }

    }
}

Someone could tell me how to solve this problem?

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

  • http://stackoverflow.com/a/25986715/2303865

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 JSON (Nsdictionary) is invalid.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.