Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

application/json needs to be handled on the ApiPostController.php #19

Open
@asantossmw

Description

@asantossmw

#I was having issues when submitted data to the backend, the controller was unable to get the message parameter. In order to process requests that haveContent-Type: application/json header defined I added the following code on theApiPostController.php file:

/**     * @Rest\Post("/api/post/create", name="createPost")     * @param Request $request     * @return JsonResponse     * @IsGranted("ROLE_FOO")     */publicfunctioncreateAction(Request$request):JsonResponse    {// Added this in order to handle requests with Content-Type: application/jsonif (0 ===strpos($request->headers->get('Content-Type'),'application/json')) {$data =json_decode($request->getContent(),true);$request->request->replace(is_array($data) ?$data :array());        }$message =$request->request->get('message');$postEntity =$this->postService->createPost($message);$data =$this->serializer->serialize($postEntity,'json');returnnewJsonResponse($data,200, [],true);    }

I don't know if this is the best way to do this, I'm new to Symfony.

BTW, thanks for creating this tutorial / guide was very helpful :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp