Created
January 26, 2020 07:30
-
-
Save Drawaes/2dec4bb85543bd1073a114ff9c508874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Bedrock.Framework; | |
using Bedrock.Framework.Protocols; | |
using Bedrock.Framework.Transports; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
namespace DemoHttpClient | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var sc = new ServiceCollection(); | |
sc.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Information)); | |
var sp = sc.BuildServiceProvider(); | |
var client = new ClientBuilder(sp) | |
.UseSockets() | |
.UseConnectionPooling() | |
.Build(); | |
await using (var connection = | |
await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 7777))) | |
{ | |
var httpClient = new HttpClientProtocol(connection); | |
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/info")); | |
Console.WriteLine($"We got a response {response.StatusCode} with content of {await response.Content.ReadAsStringAsync()}"); | |
} | |
Console.WriteLine("Second Request"); | |
await using (var connection = | |
await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 7777))) | |
{ | |
var httpClient = new HttpClientProtocol(connection); | |
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/info")); | |
Console.WriteLine($"We got a response {response.StatusCode} with content of {await response.Content.ReadAsStringAsync()}"); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment