[英]XMLHttpRequest cannot load URL. Invalid HTTP status code 400
I have WebApi Application and one MVC5 Applicatiion.I am sending request to webApi using angularJS from MVC5 Application.But it is not working fine when I send DELETE or POST request. 我有一个WebApi应用程序和一个MVC5应用程序。我正在使用MVC5应用程序中的angularJS向webApi发送请求。但是,当我发送DELETE或POST请求时,它不能正常工作。 I am getting 'XMLHttpRequest cannot load URL.
我收到'XMLHttpRequest无法加载URL。 Invalid HTTP status code 400' error in Browser.But it is working fine for GET request.See the below code.
浏览器中无效的HTTP状态代码400'错误,但是对于GET请求可以正常工作,请参见以下代码。
Sevice call 服务电话
$http.delete("http://localhost:8643/api/values/1");
WebApi 的WebAPI
// DELETE api/values/5
[HttpDelete]
public void Delete(int id)
{
var emp = employees.FirstOrDefault(x => x.ID == id);
if(emp!=null)
{
employees.Remove(emp);
}
}
Even I have enabled Cors in my WebApi. 甚至我在WebApi中都启用了Cors。 Can anyone please help me.
谁能帮帮我吗。
For the post try to add $.param to your object, and specify the content type. 对于帖子,请尝试将$ .param添加到您的对象,然后指定内容类型。 Something like that.
这样的事情。
$http({ method: "POST", url: "http://localhost:8643/api/values", data: $.param({'Type': 'Type', 'Name': 'Name'}), headers: {'Content-Type': 'application/x-www-form-urlencoded',} })
Hope this might help. 希望这会有所帮助。 As for Delete and Put, I am still having problems with them myself.
至于删除和放置,我自己仍然遇到问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.