我有以下代码对网站进行POST:
private static void Submit()
{
string formUrl = "mywebsite";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(formUrl);
req.CookieContainer = _cookieContainer;
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
string token = string.Empty;
string formParams =
string.Format("formParams");
byte[] bytes = Encoding.ASCII.GetBytes(formParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
WebResponse resp = req.GetResponse();
}
回复的回报是:
<input type='hidden' name ='FW_REQUEST_ID_TOKEN' value = '1446493462417_59.16698819328226' />
我需要做的是提取隐藏输入的值,换句话说就是&#34; 1446493 ....&#34;这样我就可以使用该信息进行另一次POST。我该如何提取它?
答案 0 :(得分:1)
如果您考虑使用DOM Parser。您可以从here
安装HTML Agility Pack安装完成后,您可以在HTML文档中加载响应。
string htmlResult = client.UploadString("URL", "POST", "data to post");
var doc = new HtmlDocument();
doc.LoadHtml(htmlResult);
获取所有输入后,按Id查找输入。
var inputTags = doc.DocumentNode.Descendants("input").ToList();