Using WebRequest.ContentLength
本文关键字:ContentLength WebRequest Using | 更新日期: 2023-09-27 18:32:29
string name = textBox.Text;
string favColour = textBox1.Text;
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "name=" + name + "&favColour" + favColour;
byte[] data = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("mywebsite.com");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.Get;
Visual Studio 2015 有一个问题,request.ContentLength.It 说 WebRequest 中没有 ContentLength 的定义。
你可以
尝试投射到HttpWebRequest
:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("mywebsite.com");
此外,通常不需要手动设置 ContentLength
属性,因为它将在写入请求流时自动完成。