在 Postman 中将枚举值作为正文发送中将、正文、Postman

2023-09-09 21:02:50 作者:┕癡ηi笑┕

我正在尝试使用邮递员调用我的 API,但我面临的问题是我的 API 正在使用将枚举对象作为主体的 PUT 方法.我怎样才能在邮递员中发送枚举..请帮忙.

I'm trying to call my API using postman, but the problem I'm facing is my API is using PUT method which takes enum object as a body.. How can I send enum in postman.. please help.

export enum TestStatus {
    allCandidates,
    completedTest,
    expiredTest,
    blockedTest
}

这是我的枚举,我正在使用 Angular 2.

this is my enum , I'm using Angular 2.

推荐答案

如果你有一个以 [FromBody]TestStatus status 为参数的方法.

Providing you have a method that takes [FromBody]TestStatus status as a parameter.

点击Body标签并选择raw,然后选择JSON(application/json).

使用这个 Json: Click on Body tab and select raw, then JSON(application/json).

Use this Json:

{
    "TestStatus": "expiredTest"
}

javax.validation.constraints 自定义注解验证枚举值

发送!

Send!

我认为上面是您所说的情况:以枚举对象为主体".以下是一些更琐碎的成分:如果您有像 [FromBody]MyClass class 这样的参数,并且它的定义为

I think above is your case as you stated: "take enum object as a body". Below are some more trivial ingredients: If you have a parameter like [FromBody]MyClass class and its definition as

public class MyClass
{
    public Guid Id { get; set; }
    public TestStatus ClassStatus { get; set; }
}

然后你修改你的 Json 为:

Then you modify your Json as:

{
    "Id": "28fa119e-fd61-461e-a727-08d504b9ee0b",
    "ClassStatus": "expiredTest"
}