我必须使用多个参数向 Web 服务发送 POST 请求,其中一个参数具有 byte[] 类型。但我不知道如何传递 byte[] 参数。有人知道吗?另外,我想知道如何在 GET 请求中发送 byte[] 数组。任何帮助将不胜感激!
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["thing1"] = "hello";
values["thing2"] = "world"; // how to pass byte[] here?
var response = client.UploadValues("http://www.example.com/recepticle.aspx", values);
var responseString = Encoding.Default.GetString(response);
}
或 HttpClient 的另一个变体:
private static readonly HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" } // how to pass byte[] here?
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();