C# 使用HttpWebRequest发送二进制数据

C# 使用HttpWebRequest发送二进制数据,c#,post,httpwebrequest,C#,Post,Httpwebrequest,我想从我的WinForms c应用程序发送一些二进制数据 服务器希望使用POST请求发送数据。我需要发送几个文件和参数,如下所示: file1=<binary data> file2=<binary data> desc1=<string> desc2=<string> 但我不明白如何使用此代码发送几个参数?我如何为每一个设置名称 使用GET我可以做&file=…&file2=…&desc1=…&desc2=…但是使用POST我不知道该做什么。你

我想从我的WinForms c应用程序发送一些二进制数据

服务器希望使用
POST
请求发送数据。我需要发送几个文件和参数,如下所示:

file1=<binary data>
file2=<binary data>
desc1=<string>
desc2=<string>
但我不明白如何使用此代码发送几个参数?我如何为每一个设置名称


使用
GET
我可以做
&file=…&file2=…&desc1=…&desc2=…
但是使用
POST
我不知道该做什么。

你能使用HttpClient吗?因为您可以使用@folibis发布json负载,即ContentType=“application/json”选项吗?这会让你们发布一些类似字典的东西。谢谢大家!HttpClient解决方案看起来正是我所需要的。我现在就去试试。不幸的是,我无法更改服务器行为。
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://example.com");
webRequest.Method = "POST";
webRequest.ContentType = "multipart/form-data";
webRequest.ContentLength = data.Length;
using (Stream postStream = webRequest.GetRequestStream())
{
    postStream.Write(data, 0, data.Length);
    postStream.Close();
}