Skip to content

Instantly share code, notes, and snippets.

@Drawaes
Created January 26, 2020 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drawaes/2dec4bb85543bd1073a114ff9c508874 to your computer and use it in GitHub Desktop.
Save Drawaes/2dec4bb85543bd1073a114ff9c508874 to your computer and use it in GitHub Desktop.
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