KeyValuePair的查询字符串应该是什么样的?

时间:2017-09-13 13:21:43

标签: c# .net asp.net-web-api

如果我将方法设置为:

[HttpPut({path})]
public async Task<IActionResult> DoSomething(sting path, IEnumerable<KeyValuePair<string,string>> values)

查询字符串应该是什么样的? (就好像我在浏览器中输入它们进行测试一样)

修改

我已经尝试了

http://localhost:12345/APath?values[0].Key=AKey&values[0].Value=MyValue

但收到404。

1 个答案:

答案 0 :(得分:0)

我将发布一个工作示例供您参考:

public class MyPerformerController: ApiController {
    [HttpPut("update/{myPath}")]
    public IActionResult PerformUpdate(string myPath, [FromBody]MyDataTransferObject myDto) {

    }
}

public class MyDataTransferObject { public string SomeProperty { get; set; } public string Salutation { get; set; } public IEnumerable<KeyValuePair<string, string>> Pairs { get; set; } }

执行PUT来电:http://localhost:12345/api/myperformer/update/aPath

body:json格式应为

{ SomeProperty: "asd", Salutation: "Mr", Pairs: [ {key: 'key1', value: 'value1'}, {key: 'key2', value: 'value2'}, ] }

请务必设置Content-Type: application/jsonAccept: application/json

修改 包括Postman的截图(Http Put通话) http put call from postman