コード例 #1
0
        public async Task Get_RequestUrlAndAuthHeader_RequestMessageMethodIsGet()
        {
            // Arrange
            const string requestUrl = "http://abc123.def/456";

            HttpRequestMessage message = null;

            var mockHttpMessageHandler = new Mock <HttpMessageHandler>();

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task <HttpResponseMessage> .Factory.StartNew(() =>
                                                                  new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{}")
            }))
            .Callback((HttpRequestMessage m, CancellationToken t) => message = m);

            var http = new RestHttpClient(new HttpClient(mockHttpMessageHandler.Object));

            // Act
            await http.Get(requestUrl);

            // Assert
            Assert.AreEqual(HttpMethod.Get, message.Method);
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            using (var host = CreateWebHostBuilder(args).Build())
            {
                host.Start();

                var httpClient = new HttpClientBuilder()
                                 .WithDefaultHeaders()
                                 .WithLogging(host.Services.GetService <ILoggerFactory>())
                                 .Build();

                httpClient.BaseAddress = new Uri("http://localhost:5000/api/");

                var restClient = new RestHttpClient(httpClient);
                var result     = restClient.Get("test").GetAwaiter().GetResult();

                Console.WriteLine($"API response content: '{result}'");
                Console.WriteLine("Press any key to quit...");
                Console.Read();

                host.StopAsync().Wait();
            }
        }
コード例 #3
0
 public async Task <ExampleResponseObject> CallGetObject(object queryData)
 {
     return(await RestHttpClient.Get <ExampleResponseObject>("https://example.com", queryData));
 }
コード例 #4
0
 public async Task <string> CallGet(object queryData)
 {
     return(await RestHttpClient.Get("https://example.com", queryData));
 }
 public Task <string> Get()
 {
     return(RestHttpClient.Get("https://example.com"));
 }