有谁知道如何在 .Net 4.5 中使用 HttpClient
和 multipart/form-data
上传?
Does anyone know how to use the HttpClient
in .Net 4.5 with multipart/form-data
upload?
我在互联网上找不到任何示例.
I couldn't find any examples on the internet.
我的结果是这样的:
public static async Task<string> Upload(byte[] image)
{
using (var client = new HttpClient())
{
using (var content =
new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
{
content.Add(new StreamContent(new MemoryStream(image)), "bilddatei", "upload.jpg");
using (
var message =
await client.PostAsync("http://www.directupload.net/index.php?mode=upload", content))
{
var input = await message.Content.ReadAsStringAsync();
return !string.IsNullOrWhiteSpace(input) ? Regex.Match(input, @"http://w*.directupload.net/images/d*/w*.[a-z]{3}").Value : null;
}
}
}
}
这篇关于C# HttpClient 4.5 多部分/表单数据上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!