我正在尝试发送帖子请求来模拟使用C#HTMLWebRequest按下位于网页表单上的按钮。网页上的表单如下所示:
<form method="post" action="HtmlAdaptor">
<input type="hidden" name="action" value="invokeOp">
<input type="hidden" name="name"
value='somevalue'>
<input type="hidden" name="methodIndex" value="5">
<hr align='left' width='80'>
<h4>java.util.List methodName()</h4>
<p>MBean Operation.</p>
<input type="submit" value="Invoke">
</form>
我发送HTML帖子并阅读HTML回复的代码:
string webURL = "http://pageurl";
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(webURL);
myRequest.Method = "POST";
byte[] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(sb.ToString());
myRequest.ContentType = "text/xml; charset=utf-8";
myRequest.ContentLength = lbPostBuffer.Length;
myRequest.Accept = "text/xml";
Stream loPostData = myRequest.GetRequestStream();
loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length);
loPostData.Close();
HttpWebResponse loWebResponse = (HttpWebResponse)myRequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc);
string lcHtml = loResponseStream.ReadToEnd();
loWebResponse.Close();
loResponseStream.Close();
我有一个字符串构建器变量“sb”,它被转换为要发布到站点的字节数组。我的问题是我不确定我应该在sb.ToString()中发送什么来提交该表单上的调用按钮。
答案 0 :(得分:0)
我通过使用fiddler找到了请求的格式。