Skip to content

Instantly share code, notes, and snippets.

@jkiddo
Created May 17, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkiddo/ece6cf3cccd5a6b01a9773717462af88 to your computer and use it in GitHub Desktop.
Save jkiddo/ece6cf3cccd5a6b01a9773717462af88 to your computer and use it in GitHub Desktop.
// https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client
// https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/bson-support-in-web-api-21
private async Task doPostAsync(byte[] document)
{
var someUrl = "http://localhost:4567";
var parametersToAdd = new Dictionary<string, string> { { "resource", "foo" } };
var newUri = QueryHelpers.AddQueryString(someUrl, parametersToAdd);
var client = new HttpClient(){ BaseAddress = new Uri(someUrl)};
var result = await client.PostAsync("docs", new ByteArrayContent(document));
result.EnsureSuccessStatusCode();
}
private async Task<byte[]> doGetAsync(string id)
{
var someUrl = "http://localhost:4567";
var parametersToAdd = new Dictionary<string, string> { { "some", id } };
var newUri = QueryHelpers.AddQueryString(someUrl, parametersToAdd);
var client = new HttpClient() { BaseAddress = new Uri(someUrl) };
var result = await client.GetByteArrayAsync("id");
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment