I need to connect Salesforce with external system using REST API. I am connecting Salesforce with external system using Username and password.
While connecting I get error code : 302
I have attached my code.
I read the documentation but couldn't get any idea to connect this.
Code:
public class AuthCallout {
public void basicAuthCallout(){
HttpRequest req = new HttpRequest();
req.setHeader('Authorization','OAuth ');
req.setHeader('Accept-Encoding','gzip,deflate');
req.setHeader('Content-Type','application/json');
//req.setMethod('GET');
req.setEndpoint('https://api.xero.com/api.xro/2.0/');
req.setMethod('GET');
// Specify the required user name and password to access the endpoint
// As well as the header and header information
String username = 'xxxxxxx';
String password = '@@@@@@@@@@';
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();
try {
HTTPResponse res = http.send(req);
System.debug('Xero'+res.getBody());
}
Catch(Exception Ex) {
System.Debug(Ex.getmessage());
}
}
}