Web API 2 POST request simulation in POSTMAN Rest Client

前端 未结 1 1472
陌清茗
陌清茗 2020-12-24 06:05

I am using ASP.NET Web API 2 with attribute routing.

I have the following PlayerModel.

public class PlayerModel
{
    public int Id {          


        
1条回答
  •  既然无缘
    2020-12-24 06:43

    Well, make sure that you specify raw and set the Content-Type request header to application/json. And then go ahead and specify the body of the POST request that will match your view model structure:

    {
        "id": 1,
        "key": "some key",
        "name": "some name of course",
        "password": "the hyper secret",
        "teamId": 256,
        "stat": {
            "playerId": 115,
            "firstName": "John",
            "lastName": "Smith",
            "title": "His Royal Majesty",
            "emailAddress": "john.smith@buckingampalace.com",
            "phoneNumbers": [
                { "value": "123", "extension": "05" },
                { "value": "456", "extension": "45" }
            ],
            "teamId": 678
        }
    }
    

    So your actual payload's gonna look like that at protocol level:

    POST /NFL/Players HTTP/1.1
    Host: localhost:9888
    Content-Type: application/json
    Content-Length: 582
    
    {
        "id": 1,
        "key": "some key",
        "name": "some name of course",
        "password": "the hyper secret",
        "teamId": 256,
        "stat": {
            "playerId": 115,
            "firstName": "John",
            "lastName": "Smith",
            "title": "His Royal Majesty",
            "emailAddress": "john.smith@buckingampalace.com",
            "phoneNumbers": [
                { "value": "123", "extension": "05" },
                { "value": "456", "extension": "45" }
            ],
            "teamId": 678
        }
    }
    

    0 讨论(0)
提交回复
热议问题