Skip to content

Instantly share code, notes, and snippets.

View ByteDev's full-sized avatar
:octocat:

ByteDev

:octocat:
View GitHub Profile
public class JsonContent : StringContent
{
    public JsonContent(string content)
        : this(content, Encoding.UTF8)
    {
    }

    public JsonContent(string content, Encoding encoding)
 : base(content, encoding, "application/json")
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
var request = new HttpRequestMessage(HttpMethod.Get, "api/orders");

var mt = new MediaTypeWithQualityHeaderValue("application/json");

request.Headers.Accept.Add(mt);
var mt = new MediaTypeWithQualityHeaderValue("application/json");

client.DefaultRequetHeaders.Accept.Add(mt);
var client = new HttpClient(new UnauthorizedResponseHandler());

var response = await client.GetAsync("https://www.google.com/");

// response.StatusCode == HttpStatusCode.Unauthorized
public class UnauthorizedResponseHandler : HttpMessageHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
        
        return Task.FromResult(response);
    }
}
@ByteDev
ByteDev / DevToolWebsites.md
Last active April 3, 2024 13:40
Dev Tool Websites
@ByteDev
ByteDev / NUnitDotnetCoreProject.md
Last active May 20, 2021 03:33
How to quicky create a new .NET Core NUnit test project.

Creating a NUnit test project

1. Create new .NET Core project

Delete any Program.cs file that might have been automatically added to the project.

2. Edit the .csproj file

Remove:

@ByteDev
ByteDev / AzureTools.md
Last active September 6, 2022 06:58
Azure tools for Windows