Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HttpsURLConnection conn =
- Util.getUrlConnection("https://test.salesforce.com/services/oauth2/token");
- conn.setDoOutput(true);
- conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- conn.setRequestProperty("charset", "utf-8");
- conn.setUseCaches(false);
- String urlParameters = String.format("grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s",
- (Object[])new String[] {SalesforceCommunicator.APP_CONSUMER_KEY, SalesforceCommunicator.APP_CONSUMER_SECRET, credentials.first, credentials.second});
- byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
- conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
- DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
- wr.write(postData);
- String response = Util.readResponse(conn.getInputStream());
- JSONObject jsonResponse = new JSONObject(response);
Add Comment
Please, Sign In to add comment