简体   繁体   English

XMLHttpRequest无法加载URL。 无效的HTTP状态代码400

[英]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.

相关问题 xmlhttprequest无法加载响应URL。 预检的$ http.delete的HTTP状态代码无效405 - xmlhttprequest cannot load response URL. for preflight has invalid http status code 405 for $http.delete XMLHttpRequest无法加载URL。 飞行前的响应具有无效的HTTP状态代码404 - XMLHttpRequest cannot load URL. Response for preflight has invalid HTTP status code 404 XMLHttpRequest无法加载URL无效的HTTP状态代码401 AngularJs - XMLHttpRequest cannot load URL Invalid HTTP status code 401 AngularJs XMLHttpRequest无法加载URL响应以进行预检具有无效的HTTP状态代码404 - XMLHttpRequest cannot load url Response for preflight has invalid HTTP status code 404 XMLHttpRequest无法加载[url]预检响应具有无效的HTTP状态代码405 - XMLHttpRequest cannot load [url] Response for preflight has invalid HTTP status code 405 仅限Chrome中的错误:预检前XMLHttpRequest无法加载URLResponse具有无效的HTTP状态代码400 NgResource-AngularJS - Error in Chrome only: XMLHttpRequest cannot load URLResponse for preflight has invalid HTTP status code 400 NgResource-AngularJS IONIC 1 XMLHttpRequest无法加载预检响应具有无效的HTTP状态代码405 - IONIC 1 XMLHttpRequest cannot load Response for preflight has invalid HTTP status code 405 XMLHttpRequest无法加载url。 在预检响应中,Access-Control-Allow-Methods不允许使用方法PUT - XMLHttpRequest cannot load url. Method PUT is not allowed by Access-Control-Allow-Methods in preflight response XMLHttpRequest无法加载URL。 Access-Control-Allow-Origin不允许原点 - XMLHttpRequest cannot load URL. Origin not allowed by Access-Control-Allow-Origin XMLHttpRequest无法加载http - XMLHttpRequest cannot load http
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM