Пример #1
0
        public bool AddAesKey(string path, AesKeyPost post)
        {
            if (!IsAuthorized())
            {
                ReAuthorise();
            }

            StringBuilder localBoxUrl = new StringBuilder();

            localBoxUrl.Append(_localBox.BaseUrl);
            localBoxUrl.Append("lox_api/key");
            localBoxUrl.Append(path);

            string AccessToken = _authorization.AccessToken;

            var handler = new HttpClientHandler {
            };

            using (var httpClient = new HttpClient(handler))
            {
                httpClient.MaxResponseContentBufferSize         = int.MaxValue;
                httpClient.DefaultRequestHeaders.ExpectContinue = false;
                httpClient.DefaultRequestHeaders.Add("x-li-format", "json");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Uri.EscapeDataString(AccessToken));

                var jsonString = JsonConvert.SerializeObject(post, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                var httpRequestMessage = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri(localBoxUrl.ToString()),
                    Content    = new StringContent(jsonString)
                };

                try
                {
                    var response = httpClient.SendAsync(httpRequestMessage).Result;

                    return(response.IsSuccessStatusCode);
                }
                catch (Exception ex) {
                    Insights.Report(ex);
                    return(false);
                }
            }
        }
Пример #2
0
        public bool AddAesKey(string path, AesKeyPost post)
        {
            if (!IsAuthorized ()) {
                ReAuthorise ();
            }

            StringBuilder localBoxUrl = new StringBuilder();
            localBoxUrl.Append(_localBox.BaseUrl);
            localBoxUrl.Append("lox_api/key");
            localBoxUrl.Append(path);

            string AccessToken = _authorization.AccessToken;

			var handler = new HttpClientHandler {};

            using (var httpClient = new HttpClient(handler))
            {
                httpClient.MaxResponseContentBufferSize = int.MaxValue;
                httpClient.DefaultRequestHeaders.ExpectContinue = false;
                httpClient.DefaultRequestHeaders.Add("x-li-format", "json");
				httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", Uri.EscapeDataString (AccessToken));

                var jsonString = JsonConvert.SerializeObject(post, new JsonSerializerSettings() {
                    NullValueHandling = NullValueHandling.Ignore
                });
                var httpRequestMessage = new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    RequestUri = new Uri(localBoxUrl.ToString()),
                    Content = new StringContent(jsonString)
                };

                try
                {
                    var response = httpClient.SendAsync(httpRequestMessage).Result;

                    return response.IsSuccessStatusCode;
                }
				catch (Exception ex){
					Insights.Report(ex);
                    return false;
                }
            }
        }