在 Postman 中将枚举值作为正文发送 [英] Send enum value as body in Postman

查看:17
本文介绍了在 Postman 中将枚举值作为正文发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用邮递员调用我的 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"
}

  • 发送!

  • 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"
    }
    

    这篇关于在 Postman 中将枚举值作为正文发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆