Disable CSRF when registering by a post method a new user in FOSUserBundle

  csrf, fosuserbundle, php, symfony

I’m looking to combine a post rest method and FOSUserBundle to my symfony 3 application to register new user, so the problem is that when i use to post a new user I got this error Bad Request with "The CSRF token is invalid. Please try to resubmit the form

here is the page that appears when i use to post a new user

This is the registration method :

class DefaultController extends BaseController

 * @Route("/register", name="registermethod")
public function registerAction(Request $request)

    $usermane = $request->query->get('username');
    $password = $request->query->get('password');
    $email = $request->query->get('email');
    /** @var $formFactory FactoryInterface */
    $formFactory = $this->get('fos_user.registration.form.factory');
    /** @var $userManager UserManagerInterface */
    $userManager = $this->get('fos_user.user_manager');
    /** @var $dispatcher EventDispatcherInterface */
    $dispatcher = $this->get('event_dispatcher');

    $user = $userManager->createUser();

    $event = new GetResponseUserEvent($user, $request);
    $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);

    if (null !== $event->getResponse()) {
        return $event->getResponse();
    $form = $formFactory->createForm();



    if ($form->isSubmitted()) {
        if ($user->getUsername() != null) {

            $event = new FormEvent($form, $request);
            $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);


             * Add new functionality (e.g. log the registration) *
                sprintf("New user registration: %s", $user)

            if (null === $response = $event->getResponse()) {
                $url = $this->generateUrl('fos_user_registration_confirmed');
                $response = new RedirectResponse($url);

            $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

            return $response;

        $event = new FormEvent($form, $request);
        $dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);

        if (null !== $response = $event->getResponse()) {
            return $response;

    return $this->render('@FOSUser/Registration/register.html.twig', array(
        'form' => $form->createView(),

I’use to post to this method in my angular application so the link is like this http://localhost:8000/showing1?username=azaz&[email protected]&password=123456789

Thank you in advance.

Source: Symfony Questions