POST Angular 2 application/json

Discussão em 'Angular' iniciado por Yanu312, Fevereiro 11, 2025.

  1. Yanu312

    Yanu312 Guest

    I am currently developing and app with Angular 2, but am hitting some problems when using the POST data to the API.

    Below is how I set the Headers and Options in Angular.

    const object = {
    AccessToken: accessToken,
    Item: {
    Id: role.Id,
    Name: role.Name,
    AuthorizedThreshold: role.AuthorizedThreshold
    }
    };
    const url = this.serverUrl + '/api/Role/Update';
    const myHeaders = new Headers();
    myHeaders.set('Content-Type', 'application/json');
    myHeaders.set('Accept', 'application/json');
    const options = new RequestOptions({ headers: myHeaders });

    return this.http.post(url, object, options).map((res: Response) => res.json());


    Whenever I try to make a POST a error 405 occurs.

    [​IMG]

    Then this is that then, when I mock the call with Postman, setting the header and content type to 'application/json', it works using the same payload.

    Below please find the Postman results.

    [​IMG]

    The below was set in the WebConfig API

    <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>


    Anyone has encountered this issue?

    Continue reading...

Compartilhe esta Página