Forked from swapnilshrikhande/apex_basix_authentication.cls
          
        
    
          Last active
          April 28, 2016 15:26 
        
      - 
      
- 
        Save mangeshpawar/6c22611149ac01ea5a5c6c277a0f7722 to your computer and use it in GitHub Desktop. 
    AuthCallout basic authentication salesforce
  
        
  
    
      This file contains hidden or 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 class AuthCallout { | |
| public void basicAuthCallout(){ | |
| HttpRequest req = new HttpRequest(); | |
| req.setEndpoint('http://www.yahoo.com'); | |
| req.setMethod('GET'); | |
| // Specify the required user name and password to access the endpoint | |
| // As well as the header and header information | |
| String username = 'myname'; | |
| String password = 'mypwd'; | |
| Blob headerValue = Blob.valueOf(username + ':' + password); | |
| String authorizationHeader = 'Basic ' + | |
| EncodingUtil.base64Encode(headerValue); | |
| req.setHeader('Authorization', authorizationHeader); | |
| // Create a new http object to send the request object | |
| // A response object is generated as a result of the request | |
| Http http = new Http(); | |
| HTTPResponse res = http.send(req); | |
| System.debug(res.getBody()); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment