C# 上传文件添加附加参数

using (var client = new HttpClient())
{
    using (var multipartFormDataContent = new MultipartFormDataContent())
    {
        var values = new[]
        {
            new KeyValuePair("c", "3"),
            new KeyValuePair("c", "2"),
            new KeyValuePair("d", "2")
             //other values
        };

        foreach (var keyValuePair in values)
        {
            multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
                String.Format(""{0}"", keyValuePair.Key));
        }

        multipartFormDataContent.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(@"D:	est.jpg")),
            ""pic"",
            ""test.jpg"");

        var requestUri = "http://localhost:8080";
        var html = client.PostAsync(requestUri, multipartFormDataContent).Result.Content.ReadAsStringAsync().Result;
    }
}
 
原文地址:https://www.cnblogs.com/xietianjiao/p/14958445.html