· 9 years ago · Jan 25, 2017, 05:26 PM
1HttpClient httpclient2 = new DefaultHttpClient();
2HttpPost post = new HttpPost("https://instance.salesforce.com/services/oauth2/token");
3List<NameValuePair> params = new ArrayList<NameValuePair>();
4params.add(new BasicNameValuePair("client_id", CONSUMER_KEY));
5params.add(new BasicNameValuePair("client_secret", SECRET_KEY));
6params.add(new BasicNameValuePair("grant_type", "password"));
7params.add(new BasicNameValuePair("username", "emailaddress"));
8params.add(new BasicNameValuePair("password", password+securityToken));
9post.setEntity(new UrlEncodedFormEntity(params));
10HttpResponse response = httpclient2.execute(post);
11String body = EntityUtils.toString(response.getEntity());
12System.out.println(body);