For example I want to connect to http://www.google.com and get DOM.
In Anonymous Window I have code:
String url = 'http://www.google.com/';
HttpRequest req = new HttpRequest();
Http https = new Http();
req.setEndpoint(url);
//req.setHeader('Content-Type','text/html');
req.setMethod('GET');
HttpResponse res = https.send(req);
//String str = res.getBody();
//System.debug(str);
Dom.Document doc = res.getBodyDocument();
But I get the error from getBodyDocument()
System.XmlException: unexpected markup <!d (position: START_DOCUMENT seen <!d... @1:3)
before <!doctype >
getBody() returns < and > (not <
and >
).
Even though I tried replace from <
and >
to < and >.
Thanks.
Any site. Maybe any site)