C# 它不会使用webrequest向网站发送文本

C# 它不会使用webrequest向网站发送文本,c#,httpwebrequest,send,httpwebresponse,C#,Httpwebrequest,Send,Httpwebresponse,我想通过编程将数据发送到网站,然后通过编程单击提交按钮。这是我试图填充的HTML代码: <textarea id="rpslBox:postRpsl:rpslObject" name="rpslBox:postRpsl:rpslObject" class="ripe-input-field ui-corner-all" rows="18" style="width:500px;"></textarea> 当我运行此代码时,它返回页面的HTML代码,而不发送此文本。我怎么

我想通过编程将数据发送到网站,然后通过编程单击提交按钮。这是我试图填充的HTML代码:

<textarea id="rpslBox:postRpsl:rpslObject" name="rpslBox:postRpsl:rpslObject" class="ripe-input-field ui-corner-all" rows="18" style="width:500px;"></textarea>

当我运行此代码时,它返回页面的HTML代码,而不发送此文本。我怎么能发这篇短信?谢谢你的帮助

我无法测试这是否有效,但据我从中了解,以下代码将把postdata转换为bytedata并提交到Web服务器:

byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
之后,可以使用以下代码从Web服务器读取新响应:

byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();

是否有任何代码试图设置textarea的内容?这不说明你应该做什么吗?事实上我不明白如何点击提交按钮。request.Method=“POST”;够了吗?您在页面上尝试了示例吗?没有
request.Method=“POST”
不会提交您的数据,但这意味着当您发送表单时,应使用POST作为发送方式(即
!)我试过一个例子,我想我的问题是,我不知道如何提交。例如,如果我想登录facebook,它会停留在登录页面上,因为我无法单击“提交”。我的猜测是,你必须遵循http协议的规则,如下所述。如果您试图在postData中设置类似于
home=Cosby&favorite+flavor=flies
,会发生什么情况?