I want to publish a stream to an HTTP server (hosted by OWINHost), see the code snippet below. It works fine when I transfer String with StringContent. However, if I want to transfer a MemoryStream with a StreamContent, the stream received on the server side is empty (I checked that the MemoryStream is correct by deserializing it on the client side for testing purposes). What am I doing wrong?
on the client side:
... var request = new HttpRequestMessage(HttpMethod.Post, Configuration.ServiceBaseAddress); // this works fine! //request.Content = new StringContent("This is a test!!"); request.Content = new StreamContent(stream); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); HttpResponseMessage response = await client.SendAsync(request); ...
server side:
public class Startup { public void Configuration(IAppBuilder app) { app.Run(async context => { var stream = new MemoryStream(); await context.Request.Body.CopyToAsync(stream); stream.Seek(0, SeekOrigin.Begin);
source share