I am trying to make get request to server which returns XML:
let text = "";
this.http.get('http://example.com', {headers : headers})
.map((res:Response) => res.text()).subscribe(data => text = data);
But, text variable is empty string, how can I retrieve plain text to convert to XML or how can I directly get XML?
Your code works perfectly for me, maybe you are trying to access text before http call is finished? Have in mind that http calls are asynchronous operations. Try this out and you will see that it works perfectly:
let text = "";
this.http.get('https://jsonplaceholder.typicode.com/posts')
.map((res:Response) => res.text())
.subscribe(
data => {
text = data;
console.log(text);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With