0
I’m trying to consume a REST service that has a basic authentication with angular 6 but I’m not succeeding follow the code I’m using unsuccessfully:
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 receive in 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 on how to make this requisition?
NOTE: I was able to make it work by creating a proxy file in my project and starting Node (ng serve) with --proxy solution (Gambiarra) taken from this site [https://medium.com/@gigioSouza/solving-the-Cors-problem-with-angular-2-e-o-angular-cli-7f7cb7aab3c2] My question is whether I publish my project on the Apache server or any other will work that "Gambiarra" on localhost worked well.
Apparently it is your server that is rejecting the connection, (it seems by permission) if you can post your server controller here it would be easier to understand the problem
– Lucas Brogni
I do not have access to the controller code only of the server and web settings that in the case is Wildfly version 8
– MarceloCP
This is not angular problem, you’re making a request and it works, but on the other side there is a server that performs authentication and you’re not going through it because it has a
'Authorization', 'Basic YWRtaW46YWRtaW4='
tied to the code. That’s not how it works. You need to log in and save theBasic
in place Torage to reuse it.– Lollipop
Have an example of how to do this of storing the login in the Angular Path
– MarceloCP