Beispiel #1
0
        async Task <LCRTMServer> Fetch()
        {
            string server = await LCCore.AppRouter.GetRealtimeServer();

            string url = $"{server}/v1/route?appId={LCCore.AppId}&secure=1";

            HttpRequestMessage request = new HttpRequestMessage {
                RequestUri = new Uri(url),
                Method     = HttpMethod.Get
            };
            HttpClient client = new HttpClient();

            LCHttpUtils.PrintRequest(client, request);

            Task <HttpResponseMessage> requestTask = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            if (await Task.WhenAny(requestTask, Task.Delay(REQUEST_TIMEOUT)) != requestTask)
            {
                throw new TimeoutException("Request timeout.");
            }

            HttpResponseMessage response = await requestTask;

            request.Dispose();
            string resultString = await response.Content.ReadAsStringAsync();

            response.Dispose();
            LCHttpUtils.PrintResponse(response, resultString);

            rtmServer = JsonConvert.DeserializeObject <LCRTMServer>(resultString, LCJsonConverter.Default);

            return(rtmServer);
        }
Beispiel #2
0
        internal async Task Upload(Action <long, long> onProgress)
        {
            LCProgressableStreamContent content = new LCProgressableStreamContent(new StreamContent(stream), onProgress);

            HttpRequestMessage request = new HttpRequestMessage {
                RequestUri = new Uri(uploadUrl),
                Method     = HttpMethod.Put,
                Content    = content
            };
            HttpClient client = new HttpClient();

            request.Headers.CacheControl = new CacheControlHeaderValue {
                Public = true,
                MaxAge = TimeSpan.FromMilliseconds(31536000)
            };
            request.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
            LCHttpUtils.PrintRequest(client, request);
            HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            request.Dispose();

            string resultString = await response.Content.ReadAsStringAsync();

            response.Dispose();
            LCHttpUtils.PrintResponse(response, resultString);

            HttpStatusCode statusCode = response.StatusCode;
        }
Beispiel #3
0
        internal async Task Upload(Action <long, long> onProgress)
        {
            MultipartFormDataContent dataContent = new MultipartFormDataContent();

            dataContent.Add(new StringContent(key), "key");
            dataContent.Add(new StringContent(token), "token");
            dataContent.Add(new StreamContent(stream), "file");

            LCProgressableStreamContent content = new LCProgressableStreamContent(dataContent, onProgress);

            HttpRequestMessage request = new HttpRequestMessage {
                RequestUri = new Uri(uploadUrl),
                Method     = HttpMethod.Post,
                Content    = content
            };
            HttpClient client = new HttpClient();

            LCHttpUtils.PrintRequest(client, request);
            HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            request.Dispose();

            string resultString = await response.Content.ReadAsStringAsync();

            response.Dispose();
            LCHttpUtils.PrintResponse(response, resultString);

            HttpStatusCode statusCode = response.StatusCode;
        }