405(方法不允许),角度为2/4

时间:2018-03-10 05:57:01

标签: angular

updateUserDetails(ename,ejobtitle,edept,eunit,equal,eaqser,empid)
{

  let url = GlobalVariable.BASE_API_URL + "api/updateUserProfile";    
  let headers = new Headers({'Content-Type':'application/json'});
  let options = new RequestOptions({headers:headers});
  const body = 
  {"empno":empid,"name":ename,"jobtitle":ejobtitle,"dept":edept,"unit":eunit,"qualification":equal,"aqinservice":eaqser}

  return this.http.post(url,body,options)
  .map(resp=>resp.json());    

}

API

[Route("api/updateUserProfile")]
    [HttpPost]       
    public HttpResponseMessage updateUserProfile(HttpResponseMessage Req)
    {
        try
        {
            string postData = new System.IO.StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();

            UserMaster.Instance.UpdateUserProfile(postData);
            var JSONString = new StringBuilder();
            JSONString.Append("{");
            JSONString.Append("\"status" + "\":" + "\"ok" + "\",");
            JSONString.Append("\"message" + "\":" + "\"Record Updated successfilly." + "\"");              
            JSONString.Append("}");
            var response = Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(JSONString.ToString(), System.Text.Encoding.UTF8, "application/json");
            return response;

        }
}

我在角度4 - 405(方法不允许)

中收到错误

但它在Fiddler中完美运作。

3 个答案:

答案 0 :(得分:0)

有很多方法可以做到这一点,其中一个方法是你可以使用Object.keys()和Object.values()方法从数据中提取键和值。

      keys:Array<String>;
      values:Array<String>;
    item={"em id":"101","name":"ABC","role":"admin"};

 myFun()
    {
     this.keys=Object.keys(this.item);
      this.values=Object.values(this.item);
    }

答案 1 :(得分:0)

使用该对象的最简单方法是给它命名并访问其属性。

例如,

item = {"em id":"101","name":"ABC","role":"admin"}; 

然后像这样使用它,

console.log("em_id is " + item.em_id + "name is " + item.name + "role is" + item.role );

但是如果你真的想把它存储在变量中,那么就这样做吧,

let em_id = item.em_id;
let name = item.name;
let role = item.role;

答案 2 :(得分:0)

问题是“ 预检请求”。将OPTIONS方法添加到您的api中,然后只需返回即可。