![](/img/trans.png)
[英]POST NameValueCollection to Web API using WebClient.UploadValues for .NET 3.5
[英]WebClient.UploadValues to API. How do I get the posted values in the API?
美好的一天,
我正在使用WebClient將數據發送到API,如另一篇文章所示:
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["thing1"] = "hello";
values["thing2"] = "world";
client.Headers.Add("Username", Store.Objects.Application.Username());
client.Headers.Add("PassToken", Store.Objects.Application.User()["PassToken"].ToString());
var response = client.UploadValues(Store.Objects.Application.API_URL() + "/Company/Add", values);
var responseString = Encoding.Default.GetString(response);
}
我的問題是我無法獲取API中發布的值:
[HttpPost]
public Store.Objects.Security.Account Add(NameValueCollection values)
{
}
如何訪問發送的值?
謝謝。
我知道映射鍵/值類型集合(例如Dictionary<TKey, TValue>
會RouteValueDictionary
Dictionary<TKey, TValue>
因為它與RouteValueDictionary
發生沖突-為避免這種情況,通常最好將適當的參數放入方法簽名中,並讓MVC綁定程序處理映射。 在您的情況下,請嘗試將方法簽名更改為
[HttpPost]
public Store.Objects.Security.Account Add(string thing1, string thing2)
{
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.