.net 打开Url发送帖子
如何在.NET2中打开webbrowser并发送帖子 类似于这个html函数的东西.net 打开Url发送帖子,.net,winforms,.net,Winforms,如何在.NET2中打开webbrowser并发送帖子 类似于这个html函数的东西 <form action="http:www.url.com/get" method="post"> <input name="tt_2a" > <input type="submit" value="submit"> 我想要像上面提到的html函数一样的东西,打开一个url,发布一些东西,然后在打开的页面中查看结果。我不需要网络回复。谢谢您可以在winforms
<form action="http:www.url.com/get" method="post">
<input name="tt_2a" >
<input type="submit" value="submit">
我想要像上面提到的html函数一样的东西,打开一个url,发布一些东西,然后在打开的页面中查看结果。我不需要网络回复。谢谢您可以在winforms应用程序中使用,以便处理网页
有关使用
WebClient
发布表单数据的更多信息,请参阅和提问。您想发布如下WebRequest:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
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 ();
如果您想在幕后发布帖子(即不显示浏览器窗口/控件),以下链接可能会有所帮助: