[英]simulate a web form button click using C# HttpWebRequest
我正在嘗試發送一個發布請求,以模擬按下使用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()中發送什么內容以提交該表單上的調用按鈕。
我已經通過提琴手找到了請求的格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.