Send content using PUT method


This post demonstrates how to send content to server from a client application written in C#. A typical REST API implements PUT methods to receive content from clients. I’ve been using RestSharp for most REST requests, but this is one use case it doesn’t provide for, yet. It is fairly easy to implement using .NET’s HttpClient.

Uri uri = ...
byte[] content = ...
string contentType = ... 

HttpClient client = new HttpClient();
ByteArrayContent httpContent = new ByteArrayContent(content);
httpContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
Task<HttpResponseMessage> put = client.PutAsync(uri, httpContent);
HttpResponseMessage response = put.Result;

Task<string> read = response.Content.ReadAsStringAsync();

if (response.StatusCode == HttpStatusCode.Created)
    // use read.Result

Specify a different ssh key for each host


The ~/.ssh/config file can be edited to specify a different key/identity for each host. This is useful when you have different ssh keys setup on different git servers.

Host mycompany
    HostName mycompany.com
    User fooey
Host github.com
    IdentityFile ~/.ssh/github.key

If you specify a HostName that is different from Host, the .git/config file should use the name specified in Host. That should also be the host name used in git commands such as clone and remote.

See Simplify Your Life With an SSH Config File for more.