嗨,我不理解如何解决这个问题,任何人都可以让我知道为什么我的put方法没有得到执行。我得到错误WEB API PUT方法无法正常工作并且获取HTTP/1.1 405方法不允许
HTTP/1.1 405方法在我的PUT方法不被允许
。有什么方法可以使用ROUTE属性来调试我的PUT方法。
public class UserProfessionController : ApiController
{
//[Route("")]
public IHttpActionResult Get()
{
return Ok();
}
[HttpPut]
public HttpResponseMessage UpdateUserProfession([FromUri]string categoryCode)
{
try
{
int userId = 1;
if (String.IsNullOrWhiteSpace(categoryCode))
{
var specialitiesRepository = new UserRepository();
if(specialitiesRepository.UpdateUserProfession(userId, categoryCode) > 0)
{
return Request.CreateResponse(HttpStatusCode.Created);
}
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid Input Data");
}
else
{
throw new Exception("Category Code-" + categoryCode + "For the User " + userId + " is not valid");
}
}
catch (Exception ex)
{
var msg = new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = new StringContent(ex.Message),
ReasonPhrase = "Invalid Input Data"
};
throw new HttpResponseException(msg);
}
}
}
状态405意味着web服务器不支持所使用的方法,你的情况PUT。该错误与您的代码没有任何关系。你使用什么网络服务器? – 2014-11-22 22:11:21