I'm trying to retrieve information from a web service through an angular app, if I try from the browser everything is ok see image 200 OK if I try from angular I get a 401 no authorized. Could anyone help me?
COMPONENT.TS
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { MissioniService } from '../services/servizi/missioni.service';
@Component({
selector: 'app-servizi',
templateUrl: './servizi.component.html',
styleUrls: \['./servizi.component.css'\]
})
export class ServiziComponent implements OnInit {
obs:Observable<any>;
constructor(private service:MissioniService) { }
ngOnInit(): void {
const host='https://username:password@xmlhostname.com/11428442.xml';
//this.obs = this.service.request(host,{par : 1},'GET');
this.obs = this.service.request(host,{},'GET');
this.obs.subscribe((data:any) => {
if(!data.error){
}else{
alert(data.error);
}
});
}
}
SERVICE.TS:
export class MissioniService {
constructor(private http:HttpClient) { }
request = (url:string, parameters:any, method:string): Observable <any>=> {
return this.http.request(method, url, {
headers: {
'Content-Type': 'application/json'
},
params: parameters
}).pipe(
/*
map((data)=>{}
*/
catchError(error => {
return error;
})
);
};
}