Gtopuria Gtopuria - 10 months ago 78
TypeScript Question

Retrieve Response body as plain text or xml in Angularjs 2 HTTP GET request

I am trying to make

request to server which returns XML:

let text = "";
this.http.get('', {headers : headers})
.map((res:Response) => res.text()).subscribe(data => text = data);

variable is empty string, how can I retrieve plain text to convert to XML or how can I directly get XML?

Answer Source

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 = "";
.map((res:Response) => res.text())
    data => {
        text = data;