Skip to content

Instantly share code, notes, and snippets.

@sfdcfanboy
Created January 15, 2018 07:10
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 sfdcfanboy/3990a61d4e59a30cca14176788489724 to your computer and use it in GitHub Desktop.
Save sfdcfanboy/3990a61d4e59a30cca14176788489724 to your computer and use it in GitHub Desktop.
HttpRequest req = new HttpRequest();
req.setEndpoint('https://my_endpoint.example.com/some_path');
req.setMethod('GET');
// Because we didn't set the endpoint as a named credential,
// our code has to specify:
// - The required username and password to access the endpoint
// - 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