Skip to content

Instantly share code, notes, and snippets.

@kiran-machhewar
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiran-machhewar/9265449 to your computer and use it in GitHub Desktop.
Save kiran-machhewar/9265449 to your computer and use it in GitHub Desktop.
public with sharing class CallOutUtil {
public String data {get;set;}
public CallOutUtil(){
data = getContent(ApexPages.currentPage().getParameters().get('url'));
//encoding data so as to avoid any data loss
data = EncodingUtil.base64Encode(Blob.valueOf(data));
}
public String getContent(String url) {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
HttpResponse res = h.send(req);
return res.getBody();
}
public static String doCallout(String url){
PageReference pageRef = Page.Callout;
pageRef.getParameters().put('url',url);
System.debug(pageRef.getContent().toString());
Dom.Document doc = new Dom.Document();
doc.load(pageRef.getContent().toString());
Dom.XMLNode root = doc.getRootElement();
String response = root.getChildElement('body',null).getChildElement('customTag',null).getText();
response = EncodingUtil.base64Decode(response).toString();
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment