Last active
August 29, 2015 13:56
-
-
Save kiran-machhewar/9265449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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