I am new to Salesforce
but aware about the REST
. I'm trying to make the HTTP POST
call to get the access_token
first to call the actual GET, PUT and POST
service.
I have written the following code in developer console and same will try in test class.
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://ap5.salesforce.com/services/oauth2/token');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setHeader('client_id','3MVG9d8..z.hDcPJZPIzGJ5UZDrL7bJthAQ_v0YCxzEeG1XXXXXXXXXXXXXXXXXXXXX');
request.setHeader('client_secret','XXXXXXXXXXX');
request.setHeader('username','XXXXXXXXXXXXX.com');
request.setHeader('password','XXXXXXXXXXXXX');
request.setHeader('grant_type','password');
request.setBody('');
HttpResponse response = http.send(request);
System.debug('Response :: '+response.getBody());
I am not sure when if we need to send above data in header or body
? But when I tried using header
I get the following error. Please guide further.
Line: 15, Column: 1
System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://ap5.salesforce.com/services/oauth2/token
When I tried in REST Client, it works fine.
Apex
.