【发布时间】:2017-09-29 11:19:51
【问题描述】:
我通过 htmlagilitypack 获取网站表单,设置表单变量并尝试提交表单。一切看起来都很好,但表单提交的响应为空。
static void Main(string[] args)
{
string urlAddress = "mywebsite";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(urlAddress);
// Post link
var post = doc.GetElementbyId("post").GetAttributeValue("href", "");
doc = web.Load(post);
// get the form
var form = doc.DocumentNode.SelectSingleNode("//form[@class='picker']");
// get the form URI
string actionValue = form.Attributes["action"]?.Value;
System.Uri uri = new System.Uri(actionValue);
// Populate the form variable
var formVariables = new List<KeyValuePair<string, string>>();
formVariables.Add(new KeyValuePair<string, string>("id", "ho"));
var formContent = new FormUrlEncodedContent(formVariables);
// submit the form
HttpClient client = new HttpClient();
var response = client.PostAsync(uri, formContent);
}
有人知道为什么我的变量响应为空吗?
谢谢
【问题讨论】:
-
您是否收到回复,如果收到,开发者控制台中会显示什么内容?
-
它说:Id = 3,Status = WaitingForActivation,Method = "{null}",Result = "{Not yet computed}"
-
@user6824563,你必须
awaitTask从PostAsync返回 -
我该怎么做?我正在我的主要功能中运行所有内容
-
@user6824563 显示主要功能。这样可以提供建议。
标签: c# httpclient html-agility-pack httpresponse