대충이라도 하자

getParsedBody() 와 getBody() + Postman에서 test 본문

꼬꼬마 개발자 노트/PHP

getParsedBody() 와 getBody() + Postman에서 test

Sueeeeee
반응형

There are two types which you can bring the data from the body in PHP.

1. getParsedBody()

   : return as an array type

2.getBody()

   : return as an object type, json

 

When using getParsedBody(), you need to choose ' x-www-form-urlccoded' on Postman.

On the other hasd, for getBody(), you need to choose raw -> json  on Postman.

 

For example, you gonna bring these data from the body.

{
  "contacts": {
            "emails": [
                "yg2222@cheilpengtai.com"
            ]
  }
}

 

-  for getParsedBody() & x-www-form-urlcoded

=> contacts is an array having email and phone number

=> At the same time, email could be more than two, so it has to be an array type as well.

=> key has to be contacts[] for one array, contacts[email][] for two

    

-  for getBody() & raw->json

 

=> just put the data as json .

반응형
Comments