简体   繁体   中英

Failed to load resource: the server responded with a status of 404 (Not Found)

When i try to Update my database from Mvc-AngularJs to wcf-Rest i'm getting error as Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:9706/EmployeeService.svc/UpdatexyzData/Update/ but with the same ur when i try to hit from Fidler Its working fine

Service.Js

this.xmlDataUpdate = function (sss) {

        var ss = $http({
            url: RestApi+"/UpdatexyzData/Update/",
            method: "PUT",
            data: $httpParamSerializerJQLike(sss),
            headers: {
                 'Accept': 'application/json',
          'Content-Type': 'application/x-www-form-urlencoded ;charset=utf-8'
            }
        })
        return ss;
    }

You can enable cors by creating a global.asax file on wcf service,

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE");

        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }
}

Try to use

'Content-Type': 'application/json ;charset=utf-8'

And to disable preflight request

 app.config(function ($httpProvider) { $httpProvider.defaults.headers.common = {}; $httpProvider.defaults.headers.post = {}; $httpProvider.defaults.headers.put = {}; $httpProvider.defaults.headers.patch = {}; }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM