Skip to content

Instantly share code, notes, and snippets.

@RahulJyala7
Last active March 29, 2019 07:06
Show Gist options
  • Select an option

  • Save RahulJyala7/3eb4f4c5280e4e50ca62e630bc24e5f6 to your computer and use it in GitHub Desktop.

Select an option

Save RahulJyala7/3eb4f4c5280e4e50ca62e630bc24e5f6 to your computer and use it in GitHub Desktop.
Protobuff Custom Formatter in Web Api C#
byte[] rawBytes = ProtoBufSerializer.ProtoSerialize<LoginRequest>(loginRequest);
var client = new HttpClient();
client.BaseAddress = new Uri("http://localhost/");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/x-protobuf"));
var byteArrayContent = new ByteArrayContent(rawBytes);
byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");
var result = client.PostAsync("Api/Login", byteArrayContent).Result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment