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

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

问题描述

我正在尝试使用邮递员调用我的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状态作为参数.

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

  • 点击正文标签,然后选择原始,然后选择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"
    }
    

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

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