我的网络发布表格有问题。 我已经下载了该页面,我推断了两个必需的值( form_build_id 和 form_token ),但是一旦发送了POST,服务器就不会在POST中收到任何内容。
排除错误:
有些想法?我在那里猛击了两天!
using (WebClientEx wc = new WebClientEx())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HTMLPage = wc.DownloadString(CREAT_TICKET_URL);
string form_build_id = SearchValue(HTMLPage, "<input type=\"hidden\" name=\"form_build_id\"", "value=\"", "\" />");
string form_token = SearchValue(HTMLPage, "<input type=\"hidden\" name=\"form_token\"", "value=\"", "\" />");
string myParameters = "macchina=" + cmacExtID + "&utente=" + custExtID + "&oggetto=" + Title + "&body=" + Note + "&op=Conferma&form_build_id=" + form_build_id + "&form_token=" + form_token + "&form_id=app_form_new_ticket";
string HtmlResult = wc.UploadString(CREAT_TICKET_URL, myParameters);
}
注意:WebClientEx类继承WebClient。我将这种方法用于其他形式,例如登录和工作。
最后一个问题是:如果这种方法有误,那么执行这一系列操作的最佳方法是“下载页面,从HTML中提取值,发送帖子”?
答案 0 :(得分:1)
问题是标题! 应该为每次调用设置标题,而我认为仅在第一次设置就足够了。
using (WebClientEx wc = new WebClientEx())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HTMLPage = wc.DownloadString(CREAT_TICKET_URL);
string form_build_id = SearchValue(HTMLPage, "<input type=\"hidden\" name=\"form_build_id\"", "value=\"", "\" />");
string form_token = SearchValue(HTMLPage, "<input type=\"hidden\" name=\"form_token\"", "value=\"", "\" />");
string myParameters = "macchina=" + cmacExtID + "&utente=" + custExtID + "&oggetto=" + Title + "&body=" + Note + "&op=Conferma&form_build_id=" + form_build_id + "&form_token=" + form_token + "&form_id=app_form_new_ticket";
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(CREAT_TICKET_URL, myParameters);
}