private ApiResponse PerformRequest(HttpVerb verb, string action, object vm = null)
        {
            CheckAccessToken();

            HttpWebRequest request = WebRequestHelper.CreateRequest(verb, action);
            RequestContent content = vm != null
                ? new RequestContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(vm)), ContentFormat.Json)
                : null;
            ApiResponse response = WebRequestHelper.GetTypedResponse <ApiResponse>(request, content);

            ThrowExceptionIfError(response.Result);

            return(response);
        }
Exemple #2
0
        public void Login(string userName, string password)
        {
            try
            {
                HttpWebRequest request = WebRequestHelper.CreateRequest(HttpVerb.Post, "Token", false);

                string content      = "grant_type=password&username="******"&password="******"access_token"];
            }
            catch (UnexpectedHttpErrorException e)
            {
                if (e.HttpStatusCode == HttpStatusCode.BadRequest)
                {
                    throw new InvalidCredentialsException();
                }
                throw;
            }
        }