Angular 2 Token: Response for preflight has invalid HTTP status code 400

后端 未结 4 2054
予麋鹿
予麋鹿 2021-02-09 10:45

I have an Angular2/TypeScript application running i Visual Studio Code.

An API running in VS 2015. This is the API project: http://www.asp.net/web-api/overview/security/

4条回答
  •  广开言路
    2021-02-09 11:34

    I found that in angular 4 you have to make it like this.

    public addQuestion(data: any): Observable  {
    
        let headersObj = new Headers();
        headersObj.set('Content-Type', 'application/x-www-form-urlencoded');
    
        let requestArg: RequestOptionsArgs = { headers: headersObj, method: "POST" };
    
        var params = new URLSearchParams();
        for(let key of Object.keys(data)){ 
          params.set(key,data[key]);
        };
    
        return this.http.post(BaseApi.endpoint + 'Question', params.toString(), requestArg)
        .map((res: Response) => res.json().data);
    
      }
    

提交回复
热议问题