c# - 使用 Flurl 通过 POST 嵌套值

标签 c# .net flurl

所以我是一名 Ruby 开发者,正在研究 C#,并试图弄清楚如何在我的端点上使用 Flurl。

这是我可以使用 Ruby 成功传递的 JSON。

  {
    type: "workorder.generated",
    data: [{
        id: order.id,
        type: "orders"
      },{
        id: second_order.id,
        type: "orders"
      },{
        id: bad_order.id,
        type: "orders"
      }
    ]
  }

因此,将 C# 与 Flurl 结合使用时,我并不 100% 清楚如何构建它。

var response = await GetAPIPath()
    .AppendPathSegment("yardlink_webhook")
    .WithOAuthBearerToken(GetAPIToken())
    .PostJsonAsync(new
    {
        type = "workorder.generated",
        data = new
        {

        }

    })
    .ReceiveJson();

对于获取类似于 Ruby 示例的数据嵌套有什么帮助吗?

最佳答案

检查这个

var x = new
{
    type = "workorder.generated",
    data = new[]{ new {
        id= 1,
        type= "orders"
      },new {
        id= 2,
        type= "orders"
      },new {
        id= 3,
        type= "orders"
      }
    }
}

关于c# - 使用 Flurl 通过 POST 嵌套值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63946096/

相关文章:

c# - EF Eager 获取派生类

c# - appsettings.json 中的 Sentry 配置与 .Net Core 3 控制台应用程序中的 Serilog

c# - 用户名认证网络服务

.net - 为什么 .Net WPF DependencyProperties 必须是类的静态成员

c# - 单击相同选择时通过鼠标单击切换 CheckedListBox 项目检查状态时的奇怪行为

c# - SQLite.Net-PCL 没有这样的功能 : ToString

c# - 用户控件内的公共(public)方法 c# .net

c# - 如何在单元测试中验证 Flurl Http 中的请求正文内容?

c# - 使用 Flurl 发布 `multipart/form-data`

c# - 如何使用 HttpTest (flurl) 模拟更长的响应时间(不是超时)