Open the Program.cs file in your editor of choice and add the following lines.
var ssrfHandler = SsrfSocketsHttpHandlerFactory.Create();
using (var httpClient = new HttpClient(ssrfHandler))
{
var response = await httpClient.GetAsync("https://example.com");
Console.WriteLine(response.StatusCode);
}
Save the changed file.
Compile and run your project with the following command
dotnet run
Open the Program.cs file from the Solution Explorer window and add the following lines.
var ssrfHandler = SsrfSocketsHttpHandlerFactory.Create();
using (var httpClient = new HttpClient(ssrfHandler))
{
var response = await httpClient.GetAsync("https://example.com");
Console.WriteLine(response.StatusCode);
}
Save the changed file.
Run the project by pressing F5 or choosing Start Debugging under the Debug menu.
Open the Program.cs file from the Explorer window and add the following lines.
var ssrfHandler = SsrfSocketsHttpHandlerFactory.Create();
using (var httpClient = new HttpClient(ssrfHandler))
{
var response = await httpClient.GetAsync("https://example.com");
Console.WriteLine(response.StatusCode);
}
Save the changed file.
Run the project by pressing F5 or choosing Start Debugging under the Run menu.
The program should run without any errors, and should output two lines that say 200, the HTTP status code for a successful request.
Congratulations, you have an HttpClient with protection from SSRF!