2017-09-13 75 views
0

如果我有一個方法設置爲:KeyValuePair的查詢字符串應該是什麼樣子?

[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

你可以使用'IEnumerable values'嗎? 會讓你以這種方式調用:'http:// localhost:12345/APath?values = MyValue&values = MyValue2&values = MyValue3'。 在方法簽名你應該有: '公共異步任務 DoSomething(sting path,[FromQuery] string []值)' – meorfi

+0

我想要能夠輸入多個鍵/值對。 – PrivateJoker

+0

與AVal1,Value1 AVal2,Value2 etc ... – PrivateJoker

回答

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

編輯 包括來自Post的截圖man(Http Put call) http put call from postman

+1

這是標題... ty – PrivateJoker

相關問題