Karan Karan - 5 months ago 20
Javascript Question

Angularjs - using $http to obtain xml response rather than json

I am trying to scrape a website using angularjs / javascript.

I know that angularjs provides an

object with which I can make get requests. I have previously used this to obtain json, can I use the same object to obtain XML (HTML)? (I believe the response will be encoded using gzip).



You should be able to use $http for getting response data other than JSON. The $http documentation explains that one of the default response transforms is If JSON response is detected, deserialize it using a JSON parser. However if you request something else (for example an HTML template) response.data should have the string value of that HTML. In fact Angular uses $http for pulling down HTML for use with ngInclude, etc.

The gzip (or unzipping in this case) should be handled by the browser before the response gets to $http.