Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将对象集合发布到服务器_C#_Http_Post - Fatal编程技术网

C# 将对象集合发布到服务器

C# 将对象集合发布到服务器,c#,http,post,C#,Http,Post,我对这件事一无所知。。我想通过POST调用服务器发送包含对象的集合(列表)。 我已成功发送了一个常规字符串,但如何处理列表 request.Method = "POST"; string postData = "This is a test that posts this string to a Web server."; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "applicatio

我对这件事一无所知。。我想通过POST调用服务器发送包含对象的集合(列表)。 我已成功发送了一个常规字符串,但如何处理列表

request.Method = "POST";
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);

request.ContentType = "application/x-www-form-urlencoded";       
request.ContentLength = byteArray.Length;     
Stream dataStream = request.GetRequestStream();     
dataStream.Write(byteArray, 0, byteArray.Length);   
dataStream.Close();

WebResponse response = null;
   try
   {
     response = request.GetResponse();
     dataStream = response.GetResponseStream();

     StreamReader reader = new StreamReader(dataStream);

     string responseFromServer = reader.ReadToEnd();

     reader.Close();
     dataStream.Close();
      response.Close();
   }
   catch (WebException)
   {
       labelShowMessage.Text = "";   
   }

这完全取决于服务器期望的列表格式。你的意思是什么?你需要知道服务器期望列表的格式。好的,那么有什么格式?这与您发送文本时的格式不同?有多少种格式,就有多少种程序员。请记住,您正在发送键值对。如果是PHP,则列表可能看起来像
key[]=value&key[]=value
,而在ASP.NET中,它看起来像
key=value&key=value
,其他人可能希望看到
key=value,value
。如果您想交换对象,例如
key[0]。property=value&key[1]。property=value
,它会变得更加有趣。如果脚本希望值以某种格式编码,比如JSON,那么您必须这样做。等等您确实应该询问解析您请求的脚本的创建者。