Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string token = "";
- string responseBody;
- string serverName = "ql1cwbeta1";
- //initialize web client
- using (WebClient webClient = new WebClient())
- {
- // pull down parameters for body
- string grantType = ConfigurationManager.AppSettings["grant_type"];
- string clientId = ConfigurationManager.AppSettings["client_id"];
- string username = ConfigurationManager.AppSettings["username"];
- string password = ConfigurationManager.AppSettings["password"];
- string authMode = ConfigurationManager.AppSettings["auth_mode"];
- //add parameters in headers
- webClient.Headers.Add("Accept", "application/json");
- // adding parameters in body
- NameValueCollection values = new NameValueCollection
- {
- {"grant_type", grantType},
- {"client_id", clientId},
- {"username", username},
- {"password", password},
- {"auth_mode", authMode}
- };
- try
- {
- byte[] responseBytes = webClient.
- UploadValues("http://" + serverName + "/CherwellAPI/token?auth_mode=" + authMode + "&api_key=" + clientId, "POST", values);
- responseBody = Encoding.UTF8.GetString(responseBytes);
- }
- catch (Exception exception)
- {
- return exception;
- }
Add Comment
Please, Sign In to add comment