Error: {"error":"unsupported_grant_type","error_description":"grant type not supported"}
Code:
String username = '****@gmail.com';
String password = '***********WwmQ***';
String endPoint = 'https://test.salesforce.com/services/oauth2/token';
String clientid = '****************';
String clientsecret = '****************8';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(endPoint);
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setBody('grant_type=password'+'&client_id='+clientid+'&client_secret='+clientsecret +'&username='+username+'&password='+password);
HttpResponse res = http.send(req);
System.debug('Body ' + res.getStatusCode());
Content-Type
, you should be usingapplication/x-www-form-urlencoded