0
在远程网站上有一个页面,用户可以在表单中输入输入值,单击按钮并以输出形式得到结果。 我想发送一个请求到页面,填写必要的输入表单,提交并获得一个结果页面,输出表格填写。如何在csharp上提交后获得响应页面?
主题类似的所有线程给出代码样本是这样的:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://www.site.com");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = string.Format("inputParam=value");
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();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
response.Close();
它返回一个页面,填写输入形式,但输出领域仍是空白,就像它不会做一个提交按钮的点击。
如何从我的C#代码执行提交并接收带有输出数据的html文档?
好的,那么我只是从流中的字符串。但问题是响应不包含输出数据。 – Sindoki 2012-04-19 07:21:00
预期响应是什么? – daryal 2012-04-19 07:23:34
有一个网站网址:“http://babelfish.yahoo.com/translate_txt”。示例参数是:“lp = en_it&trtext = sea”。在响应页面中,name =“p”的元素必须具有值=“mare”,但它是空白的。 – Sindoki 2012-04-19 07:39:37