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);
}

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。