Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetRestfulExample {
- private final String serviceEndpoint= 'https://devxxxx.service-now.com/api/now/table/incident.do';
- public String Response { get; set;}
- public String Headers { get; set; }
- public void fetchData() {
- getAndParse('GET');
- }
- public void getAndParse(String GET) {
- // Get the XML document from the external server
- Http http = new Http();
- HttpRequest request = new HttpRequest();
- String userName = 'xxx';
- String password = 'xxxx';
- // Specify the required user name and password to access the endpoint
- // As well as the header and header information
- Blob headerValue = Blob.valueOf(userName + ':' + password);
- String authorizationHeader = 'BASIC ' +
- EncodingUtil.base64Encode(headerValue);
- request.setEndpoint(serviceEndpoint);
- request.setMethod('GET');
- request.setHeader('Content-Type', 'application/json');
- // Header info with remote server user name and password
- request.setHeader('Authorization', authorizationHeader);
- // timeout in milliseconds
- request.setTimeout(120000);
- HttpResponse res = http.send(request);
- System.debug(res.getBody());
- this.response=res.getBody();
- }
- }
- <apex:page controller="GetRestfulExample" action="{!fetchData}" contentType="text/plain">
- {!response}
- setHeader('Accept','application/json');
- HttpRequest req = new HttpRequest();
- Http http = new Http();
- Blob headerValue = Blob.valueOf(credentials.get('Username') + ':' + credentials.get('Password'));
- String authorizationHeader = 'BASIC ' +
- EncodingUtil.base64Encode(headerValue);
- req.setHeader('Authorization', authorizationHeader);
- req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
- req.setMethod('POST');
- req.setBody(....);
- String url = ....;
- req.setEndPoint(url);
- HTTPResponse resp = http.send(req);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement