Skip to content

Instantly share code, notes, and snippets.

@GeorgDangl
Created May 16, 2021 17:42
Show Gist options
  • Save GeorgDangl/70473da2fb96f38f0e0e4091a3dd71c1 to your computer and use it in GitHub Desktop.
Save GeorgDangl/70473da2fb96f38f0e0e4091a3dd71c1 to your computer and use it in GitHub Desktop.
DockerWebhook.cs
private async Task CallWebhookToUpdateDockerImageAsync()
{
var webhookUri = "https://username:password@app-name.scm.azurewebsites.net/docker/hook";
var uri = new Uri(webhookUri);
var httpRequest = new HttpRequestMessage(HttpMethod.Post, webhookUri);
// The webhooks for Azure App Service contain username & password, it's required for authentication
// in the webhook request
if (!string.IsNullOrWhiteSpace(uri.UserInfo))
{
var encodedStr = Convert.ToBase64String(Encoding.ASCII.GetBytes(uri.UserInfo));
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", encodedStr);
}
using var httpClient = new HttpClient();
var webhookResponse = await httpClient.SendAsync(httpRequest);
var webhookResponseContent = await webhookResponse.Content.ReadAsStringAsync();
Logger.Normal($"Received response from webhook: {webhookResponseContent}");
ControlFlow.Assert(webhookResponse.IsSuccessStatusCode, "The webhook response did not indicate a success");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment