Search code examples
angularangular2-servicesangular5

Response for preflight has invalid http status code 405 angular 5 in chrome


enter image description hereI am getting 405 error i have attached the screenshot and code for review.

getDetails(rolename: Role): Observable<Role> {
        let value = Array();
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');        
        let options = new RequestOptions({ headers: headers });
        var passData = {
            "Abc": "khkh",
            "cde": "hkhk",
            "fgh": "hkhk",
            "ijk": "acc"
        };
        let body = this.serializeObj(passData);

        return  this.http.post("http://localhost/service.svc/GetResults",           
           body,            
           options).pipe(
              map((response:  Response)  =>  {
                  debugger;
                 return  <Response>response;
              })).catch(this.handleErrorObservable);

    }

i have added cors in webconfig

<httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />        
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE,OPTIONS" />
      </customHeaders>
    </httpProtocol>

my Post method is pointing to WCF Rest

[OperationContract]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
                                   RequestFormat =WebMessageFormat.Json,
                                   BodyStyle = WebMessageBodyStyle.Wrapped,
                                   UriTemplate = "GetResults")]
        List<ResponceModel> GetResults(Model request);

I cant able to post . please help me.


Solution

  • I got the Answer

    I hosted the application in same server and tried to run in the same appdomain . so there was no cross domain issue occured. thus my issue solved. Thanks for the help guys