似乎 ASP.NET MVC Web API 中的 FormDataCollection 自动解码了这些值。有没有办法关闭它?我正在使用提琴手将以下数据发布到我的网址:
.code=2001&Color=Lam%E9%20Purple
不幸的是,颜色已经被解码,结果如下:
Lam� Purple
我希望得到的是:
Lamé Purple
使用的代码:
[HttpPost]
public HttpResponseMessage PostItem(FormDataCollection collection)
{
int qty = 5000;
var response = Request.CreateResponse(HttpStatusCode.Created);
response.StatusCode = HttpStatusCode.OK;
if (collection == null)
{
response.Headers.Add("Available", qty.ToString());
return response;
}
var item = new Item();
foreach (KeyValuePair<string, string> keyValuePair in collection)
{
switch(keyValuePair.Key)
{
case ".quantity":
item.Qty = Convert.ToInt32(keyValuePair.Value);
break;
case ".code":
item.Style = keyValuePair.Value;
break;
case "Color":
item.Color = keyValuePair.Value;
break;
case "Size":
item.Size = keyValuePair.Value;
break;
}
}
qty = Repository.GetInventory(item);
response.Headers.Add("Available", qty.ToString());
return response;
}