ANGULAR $ http.put REST [英] ANGULAR $http.put REST
本文介绍了ANGULAR $ http.put REST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用REST角度($ http)来使用Web服务。
GET没问题,但当我尝试使用$ http.put进行更改时,错误显示如下:
I try to consume a Web service with REST angular ($ http). The GET is OK, but when I try to make a change with $ http.put, the error appears below:
XMLHttpRequest cannot load http://10.2.150.238:90/api/Collaborateurs/1. Response for preflight has invalid HTTP status code 405.
更新功能:
.factory('UpdateCollaborateur', function ($http, config) {
var fac = {};
fac.Update = function (matricule,collaborateur) {
return $http.put(config.apiUrl + 'Collaborateurs/'+ matricule, collaborateur);
};
return fac;
})
WEB API 2 ,put:
WEB API 2 , put :
public IHttpActionResult PutCollaborateur(int id, Collaborateur collaborateur)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != collaborateur.matricule_collaborateur)
{
return BadRequest();
}
db.Entry(collaborateur).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!CollaborateurExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
我的功能标题:
[ResponseType(typeof(void))]
这是什么问题?
谢谢
What is this problem?? Thanks
推荐答案
405表示不允许使用该方法
405 means that the method is not allowed
如果您使用 [HttpPut]
确保您的webconfig.xml允许它
If you use [HttpPut]
make sure that's your webconfig.xml allows it
请尝试以下
<system.webServer>
<handlers>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
这篇关于ANGULAR $ http.put REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文