public async Task PostToServer() { var entity = await _entityStore.GetEntity(Data.ObjectId, false); var owner = await _entityStore.GetEntity((string)entity.Data["actor"].First().Primitive, false); var unflattened = await _entityFlattener.Unflatten(_entityStore, entity); var token = await _deliveryService.BuildFederatedJWS(owner, Data.TargetInbox); var hc = new HttpClient(); var serialized = unflattened.Serialize(true).ToString(Formatting.None); var content = new StringContent(serialized, Encoding.UTF8); content.Headers.ContentType = new MediaTypeHeaderValue("application/ld+json"); content.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("profile", "\"https://www.w3.org/ns/activitystreams\"")); var message = new HttpRequestMessage(HttpMethod.Post, Data.TargetInbox); message.Content = content; message.Headers.Date = DateTimeOffset.Now; message.Headers.TryAddWithoutValidation("Accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""); message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); message.Headers.Add("Signature", await _buildSignature(owner.Id, message)); var result = await hc.SendAsync(message); var resultContent = await result.Content.ReadAsStringAsync(); if (!result.IsSuccessStatusCode && (int)result.StatusCode / 100 == 5) { throw new Exception("Failed to deliver. Retrying later."); } }