Guest User

Untitled

a guest
Dec 28th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. string token = "";
  2. string responseBody;
  3. string serverName = "ql1cwbeta1";
  4.  
  5. //initialize web client
  6. using (WebClient webClient = new WebClient())
  7. {
  8. // pull down parameters for body
  9. string grantType = ConfigurationManager.AppSettings["grant_type"];
  10. string clientId = ConfigurationManager.AppSettings["client_id"];
  11. string username = ConfigurationManager.AppSettings["username"];
  12. string password = ConfigurationManager.AppSettings["password"];
  13. string authMode = ConfigurationManager.AppSettings["auth_mode"];
  14.  
  15. //add parameters in headers
  16. webClient.Headers.Add("Accept", "application/json");
  17.  
  18. // adding parameters in body
  19. NameValueCollection values = new NameValueCollection
  20. {
  21. {"grant_type", grantType},
  22. {"client_id", clientId},
  23. {"username", username},
  24. {"password", password},
  25. {"auth_mode", authMode}
  26. };
  27.  
  28. try
  29. {
  30. byte[] responseBytes = webClient.
  31. UploadValues("http://" + serverName + "/CherwellAPI/token?auth_mode=" + authMode + "&api_key=" + clientId, "POST", values);
  32. responseBody = Encoding.UTF8.GetString(responseBytes);
  33. }
  34. catch (Exception exception)
  35. {
  36. return exception;
  37. }
Add Comment
Please, Sign In to add comment