Created
January 15, 2018 07:10
-
-
Save sfdcfanboy/3990a61d4e59a30cca14176788489724 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
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