小编Dee*_*mar的帖子

邮递员将错误的整数值传递给 API 控制器

我在邮递员中发现了一个奇怪的问题。在下面的请求金额是整数字段。

{ "merchantId": 49, "amount": 020 }
Run Code Online (Sandbox Code Playgroud)

当我通过数量 020 而不是 20 时。在 API 控制器中,我收到数量 16。当我通过 0100 时,我收到 64。

如果我传入像“020”或“0100”这样的双引号。然后我得到 20 和 100。

下面是控制器方法和请求类:

    [HttpPost]
    public IHttpActionResult Post(XXXXXXXXCommand command)
    {
        IHttpActionResult result = null;

        using (_logger.PushWeb())
        {
            _logger.Info("POST request to /transactions/debits/accountsetup", command);
            try
            {

            }

            catch (MerchantNotFoundException ex)
            {
                _logger.Error("XXXX", ex);


            }

        }
        return result;
    }


[DataContract(Name = "XXXXCommand")]
public class XXXXXXCommand : CommandBase
{
    /// <summary>
    /// Merchant ID 
    /// </summary>
    [DataMember(Name = "merchantId", Order = 1)]
    public int MerchantId …
Run Code Online (Sandbox Code Playgroud)

api rest asp.net-web-api postman

4
推荐指数
1
解决办法
5496
查看次数

标签 统计

api ×1

asp.net-web-api ×1

postman ×1

rest ×1