我正在尝试使用HTTPWebRequest
发布C#列表。
我正在使用以下代码块,但获得
无法从“ System.Collections.Generic.List”转换为 'char []'
List<string> mylist = new List<string>();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("My_Url");
request.Method = "POST";
request.ContentType = "application/json";
Stream stream = request.GetRequestStream();
byte[] buffer = Encoding.UTF8.GetBytes(mylist);
stream.Write(buffer, 0, buffer.Length);
res = (HttpWebResponse)request.GetResponse();
预先感谢您的帮助
答案 0 :(得分:1)
根据文档,您应该将string
或char[]
或char*
传递给GetBytes()方法。
您可以使用LINQ
:
byte[] buffer = mylist.SelectMany(str => Text.Encoding.UTF8.GetBytes(str)).ToArray(); // use needed encoding