无法发送表单的 POST 数据
Unable to send POST data of a form
我的 Web Post 表单有问题。
我已经下载了页面,我推断了两个所需的值(form_build_id 和 form_token),但是一旦发送POST 服务器在 POST 中未收到任何内容。
排除的错误:
- 错误link(可以下载页面)
- 外推数据不正确(已验证)。
- 错误的字符串 myParameters(已验证)。
- 我已经手动测试了表单,它工作正常。
有什么想法吗?在那里我磕了两天头!
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);
}
Note: WebClientEx class inherits WebClient. I used this approach to other forms such as login and work.
最后一个问题是:如果这种方法是错误的,那么执行这一系列操作的最佳方法是什么"download the page, extract the values from the HTML, send post form"?
问题出在 header!
header应该每次调用都要设置,而我认为只设置第一次就足够了。
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);
}
我的 Web Post 表单有问题。 我已经下载了页面,我推断了两个所需的值(form_build_id 和 form_token),但是一旦发送POST 服务器在 POST 中未收到任何内容。
排除的错误:
- 错误link(可以下载页面)
- 外推数据不正确(已验证)。
- 错误的字符串 myParameters(已验证)。
- 我已经手动测试了表单,它工作正常。
有什么想法吗?在那里我磕了两天头!
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);
}
Note: WebClientEx class inherits WebClient. I used this approach to other forms such as login and work.
最后一个问题是:如果这种方法是错误的,那么执行这一系列操作的最佳方法是什么"download the page, extract the values from the HTML, send post form"?
问题出在 header! header应该每次调用都要设置,而我认为只设置第一次就足够了。
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);
}