Created
February 3, 2022 10:33
-
-
Save 6rube/6298932e7b1ab3a1b8d255ffeb3e55de to your computer and use it in GitHub Desktop.
Async HTTP Post Request with Auth
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 System.Net.Http.Headers; | |
HttpClient client = new HttpClient(); | |
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "TOKEN"); //Add Authentication (extra) | |
var data = @"{JSON}"; //JSON String | |
var buffer = System.Text.Encoding.UTF8.GetBytes(data); | |
var byteContent = new ByteArrayContent(buffer); | |
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); //Type Of Data | |
var response = await client.PostAsync("http://127.0.0.1/createSomething", byteContent); //URL | |
var responseString = await response.Content.ReadAsStringAsync(); | |
Console.WriteLine(responseString); //out to terminal (extra) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment