Http request with angle 6

0

I'm trying to consume a REST service that has a basic authentication with angle 6 however I'm not able to follow the code I'm using without success:

public iniciarProcesso(dadosProcesso: string): Observable<any> {
    const headers = new Headers()

    headers.append('Content-Type', 'application/json')
    headers.append('Authorization', 'Basic YWRtaW46YWRtaW4=')

    return this.http.post(
        this.API,
        dadosProcesso,
        {headers: headers}
    ).pipe(map((res) => {
        console.log(res)
        return res
        })
    )
}

I get a response:

OPTIONS http://localhost:8080/engine-rest/process-definition/key/agendarEventoTeatro/start 401 (Unauthorized)

Failed to load http://localhost:8080/engine-rest/process-definition/key/agendarEventoTeatro/start: Response for preflight does not have HTTP ok status.

Does anyone have any light how to make this request?

NOTE: I was able to create a proxy file in my project and start the node (ng serve) with --proxy solution (Gambiarra) from that site [ link My question is if I publish my project on the Apache server or any other will it work that "Gambiarra" in localhost worked fine.

    
asked by anonymous 16.08.2018 / 19:19

1 answer

-1

I started using Angular 6 recently but in this type of request I usually use this way:

func(objetoEnviado): Observable<TipoDoObjetoEnviado>{
    this.http.post<TipoDoObjetoEnviado>(linkDaApi, objetoEnviado)
}

Using a type reference of the sent variable. I do not know how your application is structured but this can help.

    
16.08.2018 / 19:39