通过 Postman 和 C# 发送包含多种类型的数组 [英] Sending array containing multiple types via Postman and C#

查看:86
本文介绍了通过 Postman 和 C# 发送包含多种类型的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是api的要求:

"merchant_uid": "{{merchant_uid}}",
    "products": [
        {
            "name": "Test",
            "price": 100,
            "quantity": 1
        }
    ],
    "return_url": "https://platform.example.com/return/",
    "notify_url": "https://platform.example.com/notify/",
    "total_price": 100

我试着像这样把所有东西都放进邮递员

I tried putting everyhing into postman like so

但这会返回一个 400 错误的请求.

But this returns an 400 bad request.

我也尝试通过 c# 执行此操作,但我无法确定给它一个包含数字和字符串的类型(我收到了 400 个错误的请求:产品必须在数组中):

I also tried doing this via c# but I cant figure out to give it a type containing numbers and strings (i received the 400 bad request: products must be in array):

var products = new
{
    name = "test",
    price = 100,
    quantity = 1
};



var postModel = new
{
    merchant_uid = merchant_uid,
    products = products,
    return_url = return_url,
    notify_url = notify_url,
    total_price = total_price,
};

var response = await client.PostAsJsonAsync(url, postModel);

所以这两种方法都不行.

So neither approach works.

你能解决这个问题吗?

谢谢!

推荐答案

如果您的控制器方法是 [HttpPost] 方法,您应该将您的条目作为 Json 发送.这样做:

If your controller method is a [HttpPost] method, you should send your entry as Json. To do it:

  • 选择发布请求

在正文部分,选择 rawJson 类型见下图:

In body section, choose raw and Json type See the picture below:

这篇关于通过 Postman 和 C# 发送包含多种类型的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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