Guest User

Untitled

a guest
Dec 15th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. HttpsURLConnection conn =
  2. Util.getUrlConnection("https://test.salesforce.com/services/oauth2/token");
  3. conn.setDoOutput(true);
  4. conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  5.  
  6. conn.setRequestProperty("charset", "utf-8");
  7. conn.setUseCaches(false);
  8.  
  9. String urlParameters = String.format("grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s",
  10. (Object[])new String[] {SalesforceCommunicator.APP_CONSUMER_KEY, SalesforceCommunicator.APP_CONSUMER_SECRET, credentials.first, credentials.second});
  11.  
  12. byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
  13. conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
  14.  
  15. DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
  16. wr.write(postData);
  17.  
  18. String response = Util.readResponse(conn.getInputStream());
  19. JSONObject jsonResponse = new JSONObject(response);
Add Comment
Please, Sign In to add comment