Angular 6 with broken Laravel/Lumen JSON

Asked

Viewed 34 times

1

Guys I’m sending an angular post to a Windows/Internet application, but my JSON arrives broken.

requisição quebrada enviada pelo Angular

Now when I send by Postman, it arrives this way.

requisição correta feita pelo postman

follows my Angular code

    cadastrar(register: Register): Observable<string>{
    const httpOptions = {
        headers: new HttpHeaders({
          'Content-Type': 'application/x-www-form-urlencoded'
        })
      };
    console.log(register)
    console.log(JSON.stringify(register))
    return this.http.post<Register>(`${URL_API}/user/create`, register, httpOptions)
    .pipe(map(register => register.USER_FIRST_NAME))
}

Code Lumen

public function store(Request $request, UserService $userService)
{
    // Função para criação e armazenamento de um novo usuário, criando também novas credenciais (chamada para MS-Auth)
    try {
        var_dump($request->all());
        // Validação dos atributos da chamada de acordo com as regras definidas no modelo de User, em 'create'
        $this->validate($request, User::$rules['create'],[]);

        // Enviando para o userService->store() apenas os campos indicados dentro do vetor only([])
        $user = $userService->store($request->only([
            "USER_FIRST_NAME",
            "USER_LAST_NAME",
            "USER_EMAIL",
            "USER_PASSWORD"
        ]));
    }

Thank you!

  • You don’t need the stringify, Angular already does it for you.

  • hello friend, I tried to pass JSON.stringify(Register), but I got the same result.

No answers

Browser other questions tagged

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