Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有谁知道如何使用 flurl 通过 url 编码形式发送带括号的字段?
示例:我想发送带有“foo”值的 foo[bar] 字段,如下所示
var response = await "https://server/request" .WithHeader("Header1", "headerValue") .PostUrlEncodedAsync(new { foo[bar] = "foo" })
C# 标识符中不允许使用括号,因此在这里使用匿名对象表示名称/值对将不起作用。但是,在 Flurl 将对象解析为名称/值对的所有情况下,它都会对字典进行特殊处理。所以你可以这样做:
var response = await "https://server/request" .WithHeader("Header1", "headerValue") .PostUrlEncodedAsync(new Dictionary<string, string>() { { "foo[bar]", "foo" } });