Ejemplo n.º 1
0
        /// <summary>
        /// Logs in using ASE credentials provided in the constructor.
        /// </summary>
        /// <returns>Token for use in further calls to the API.</returns>
        void Login()
        {
            NameValuePairs nv = new NameValuePairs();

            nv.Add("userId", Username);
            nv.Add("password", StringUtils.GetUnsecureString(Password));
            nv.Add("featureKey", DEFAULT_FEATUREKEY);

            try
            {
                HttpResponseMessage          response = Post("login", nv.ToJson()).GetAwaiter().GetResult();
                Dictionary <string, dynamic> ret      = GenericJsonParse(response);
                Client.DefaultRequestHeaders.TryAddWithoutValidation(TOKEN_NAME, ret["sessionId"]);

                Log.Debug(String.Format("Successfully logged into ASE as {1}: {0}", ret["sessionId"], Username));
            }catch (Exception e)
            {
                Log.Error(String.Format("Failed to login to ASE as {0}: {1}", Username, e.Message), e);
                throw e;
            }finally
            {
                nv = null; //clean up values from memory.
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a HTTP PUT request to the server at the requestUri given. This will append the given
        /// name value pairs into the body of the request as JSON.
        /// </summary>
        /// <param name="requestUri">Request URI</param>
        /// <param name="nameValuePairs">Name value pairs which will be sent in the body of the request as JSON.</param>
        /// <returns>Response from the server if the status code is 200</returns>
        async Task <HttpResponseMessage> Put(string requestUri, NameValuePairs nameValuePairs)
        {
            StringContent content = new StringContent(nameValuePairs.ToJson(), Encoding.UTF8, "application/json");

            return(await Put(requestUri, content));
        }