Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public class AuthCallout {
  2.  
  3. public void basicAuthCallout(){
  4. HttpRequest req = new HttpRequest();
  5. req.setEndpoint('http://www.yahoo.com');
  6. req.setMethod('GET');
  7.  
  8. // Specify the required user name and password to access the endpoint
  9. // As well as the header and header information
  10.  
  11. String username = 'myname';
  12. String password = 'mypwd';
  13.  
  14. Blob headerValue = Blob.valueOf(username + ':' + password);
  15. String authorizationHeader = 'BASIC ' +
  16. EncodingUtil.base64Encode(headerValue);
  17. req.setHeader('Authorization', authorizationHeader);
  18.  
  19. // Create a new http object to send the request object
  20. // A response object is generated as a result of the request
  21.  
  22. Http http = new Http();
  23. HTTPResponse res = http.send(req);
  24. System.debug(res.getBody());
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement