Exemple #1
0
        public string GetTokenForUser(string userName)
        {
            CheckAccessToken();

            HttpWebRequest request = WebRequestHelper.CreateRequest(HttpVerb.Get,
                                                                    "api/Account/v1/CreateTokenForUser?userName=" + userName);

            dynamic token = WebRequestHelper.GetDynamicResponse(request);

            return(token.ToString());
        }
        public Tuple <byte[], string> GetImage(int imageId)
        {
            CheckAccessToken();

            HttpWebRequest request =
                WebRequestHelper.CreateRequest(HttpVerb.Get, "api/Image/v1/GetImage?imageId=" + imageId);

            var result = Task.Run(async() => await WebRequestHelper.GetResponseBytesAsync(request)).Result;


            return(result);
        }
        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 #4
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;
            }
        }