POST a string and an image in one request using HttpClient
using Windows.Web.Http; using Windows.Web.Http.Headers; private async void Foo() { // the image var fileStream = await file.OpenReadAsync(); var streamContent = new HttpStreamContent(fileStream); var filename = "myImage.png"; // the text var text = "oompa loompas"; var stringContent = new HttpStringContent(text); // Putting all together. var formDataContent = new HttpMultipartFormDataContent(); formDataContent.Add(streamContent, "myImage", fileName); formDataContent.Add(stringContent, "myString"); // Send it to the server. var response = await (new HttpClient()).PostAsync(uri, formDataContent); }
posted on 2015-03-26 15:02 wlqsmiling 阅读(179) 评论(0) 编辑 收藏 举报