【发布时间】:2016-01-10 05:16:35
【问题描述】:
在控制器上Put如下:
[HttpPut]
[ActionName("putname")]
public JsonResult putname(string name)
{
var response = ...
return Json(response);
}
问题在于通过以下方式使用此 API 时
using (httpClient = new HttpClient())
{
string name = "abc";
string jsonString = JsonConvert.SerializeObject(name);
var requestUrl = new Uri("http:...../controller/putname/");
using (HttpContent httpContent = new StringContent(jsonString))
{
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = httpClient.PutAsync(requestUrl, httpContent).Result;
}
此代码不会将参数名称传递给控制器。我什至尝试将 uri 更改为 /putname/" + name。
【问题讨论】:
标签: c# asp.net-mvc-3 json.net