Exemple #1
0
        static void Main(string[] args)
        {
            HttpClient httpClient         = null;
            bool       interruptExecution = false;

            // Parse command line parameters
            interruptExecution = ParseCommandLineParameters(args);
            if (interruptExecution)
            {
                return;
            }

            if (requestConfig.Verbose)
            {
                Console.WriteLine("> REQUESTING {0}://{1}:{2}{3} ...", requestConfig.UseSsl ? "https" : "http", requestConfig.Host, requestConfig.Port, requestConfig.Path);
            }

            // Send request to server
            try
            {
                httpClient = new HttpClient(requestConfig.UseSsl);
                httpClient.SendGetRequest(requestConfig);
                serverResponseData = httpClient.GetServerResponse();
            }
            catch (SocketException ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
            }

            // Print server response headers and content data
            if (requestConfig.VerboseHeaders && serverResponseData != null)
            {
                DumpHeaders(serverResponseData);
            }

            // Print calculated data
            if (requestConfig.Verbose && serverResponseData != null)
            {
                Console.WriteLine("> CONTENT TRANSFER TYPE: {0}", serverResponseData.ContentTransferType);
                Console.WriteLine("> CONTENT LENGTH: {0}", serverResponseData.ContentLength);
            }

            // Print/Save server content data
            if (serverResponseData != null)
            {
                DumpData(serverResponseData, requestConfig);
            }
        }
Exemple #2
0
 public void ProcessMetaData(ResponseMetaData metaData)
 {
     if (metaData.OptionalData.TryGetValue(nameof(TmdbServiceConfiguration),
                                           out IOptionalData optionalData))
     {
         if (!TmdbServiceConfiguration.HasValue)
         {
             var tmdbServiceConfig = (TmdbServiceConfigurationInfo)optionalData;
             TmdbServiceConfiguration.SetServiceConfigurationIfNeed(tmdbServiceConfig);
         }
     }
 }
Exemple #3
0
 private static void DumpHeaders(ResponseMetaData serverResponseData)
 {
     if (serverResponseData.Headers != null && serverResponseData.Headers.Count > 0)
     {
         foreach (string key in serverResponseData.Headers.Keys)
         {
             foreach (string value in serverResponseData.Headers[key])
             {
                 Console.WriteLine("> HDR: {0}={1}", key, value);
             }
         }
     }
     else
     {
         Console.WriteLine("> HDR: No headers");
     }
 }
        public async Task <OrphansResponse> GetOrphansAsync(OrphanParametes parameters)
        {
            string queryString = $"?pageSize={parameters.PageSize}&pageNumber={parameters.PageNumber}";
            string url         = $"{ HttpRepositorySettings.BaseApiUrl }/{ Controller }{ queryString} ";

            var request = new HttpRequestMessage(HttpMethod.Get, url);

            // TODO Add JWT token to header
            // request.Headers

            var response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            IEnumerable <string> xPagination;

            response.Headers.TryGetValues("X-Pagination", out xPagination);

            ResponseMetaData metaData = null;

            if (xPagination != null)
            {
                string xPaginationData = xPagination.FirstOrDefault();
                metaData = JsonSerializer.Deserialize <ResponseMetaData>(xPaginationData, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                });
            }

            var content = await response.Content.ReadAsStringAsync();

            var orphans = JsonSerializer.Deserialize <List <Orphan> >(content, new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            });

            return(new OrphansResponse {
                Orphans = orphans, MetaData = metaData
            });
        }
Exemple #5
0
        private static void DumpData(ResponseMetaData serverResponseData, RequestConfig requestConfig)
        {
            bool isText      = serverResponseData.ContentType.ToLower().StartsWith("text/");
            bool writeToFile = !string.IsNullOrEmpty(requestConfig.ContentDataOutputFile);

            FileStream outputDataStream = null;

            if (writeToFile)
            {
                Console.WriteLine("> DMP2FILE={0}", requestConfig.ContentDataOutputFile);
                outputDataStream = File.OpenWrite(requestConfig.ContentDataOutputFile);
            }

            foreach (byte[] chunk in serverResponseData.ContentData)
            {
                if (writeToFile)
                {
                    outputDataStream.Write(chunk, 0, chunk.Length);
                }

                if (requestConfig.VerbosePayload)
                {
                    if (isText)
                    {
                        Console.WriteLine(Encoding.UTF8.GetString(chunk));
                    }
                    else
                    {
                        Console.WriteLine("> DATA: {0} bytes received", chunk.Length);
                    }
                }
            }

            if (outputDataStream != null)
            {
                outputDataStream.Close();
            }
        }
Exemple #6
0
 public ServiceResponse(TResponse data, ResponseMetaData metaData) : base(metaData)
 {
     Data = data;
 }
 public HttpClient(bool useSsl)
 {
     this.certificateErrors = new Hashtable();
     this.responseMetaData  = new ResponseMetaData();
 }
Exemple #8
0
 public ServiceResponse(ResponseMetaData metaData)
 {
     MetaData = metaData;
 }