网页API不支持POST方法 [英] Web api not supporting POST method
问题描述
在我的Web API控制器我有以下codeS功能
In my web api controller i have a function with following codes
[HttpPost]
public HttpResponseMessage Post(string schooltypeName)
{
_schoolTypeService.RegisterSchoolType(schooltypeName);
var message = Request.CreateResponse(HttpStatusCode.Created);
return message;
}
当我与小提琴手我收到此错误调用
When i am calling with fiddler i am getting this error
{"Message":"The requested resource does not support http method 'POST'."}
我摆弄参数
标题
User-Agent: Fiddler
Host: myhost:8823
Content-Type: application/json; charset=utf-8
Content-Length: 26
请求体
{"schooltypeName":"Aided"}
请求URL中
http://myhost:8823/SchoolType
(我配置的URL,得到的是工作与此网址)
( i configured url ,GET is working with this url)
请告诉我错在这里?
推荐答案
改变你的动作要像发表([FromBody]字符串schooltypeName)
由默认的字符串类型是预计将有URI。
Change your action to be like Post([FromBody]string schooltypeName)
as by default string type is expected to come Uri.
更新:结果
你的身体变化,只是辅助
你目前需要一个类来使deserialiation工作,否则(的前的一流的学校{公共字符串SchoolTypeName {获取;集;}}
Updated:
Change your body to just "Aided"
as currently you would need a class to make the deserialiation work otherwise (ex:class School { public string SchoolTypeName { get; set; } }
这篇关于网页API不支持POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!