【发布时间】:2016-03-17 12:18:11
【问题描述】:
我尝试将 HTML 表单发布到另一个 URL,在我的测试中创建了表单:
<html>
<body onload='document.forms["form1"].submit()'>
<form id='form1' method='POST' action='http://localhost:52035/testpage?'>
<input type='hidden' id='name' value='form1' />
<input type='hidden' name='NEW_ITEM["0"] value='1234-ABC'/>
</form>
</body>
</html>
但不发送,
以下是 build / send 形式的 sn-p,可通过单击按钮访问:
protected void btnSubmitRequest_Click(object sender, EventArgs e)
{
var hookUrl = SessionHelper.GetValue("hookurl").ToString();
string formId = "form1";
StringBuilder htmlForm = new StringBuilder();
htmlForm.AppendLine("<html>");
htmlForm.AppendLine(String.Format("<body onload='document.forms[\"{0}\"].submit()'>", formId));
htmlForm.AppendLine(String.Format("<form id='{0}' method='POST' action='{1}'>", formId, hookUrl));
htmlForm.AppendLine("<input type='hidden' id='name' value='form1' />");
// test values
prod.ProductCode = "1234-ABC"
int i = 0;
htmlForm.AppendLine(String.Format("<input type='hidden' name='NEW_ITEM[\"{0}\"] value='{1}'/>",i, prod.ProductCode));
htmlForm.AppendLine("</form>");
htmlForm.AppendLine("</body>");
htmlForm.AppendLine("</html>");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(htmlForm.ToString());
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
【问题讨论】:
-
您的表单没有
name="form1"。 -
哦,那应该在
<form>加载后执行。 -
嗨 Paveen,我添加了 name='form1',您是说 htmlForm 行“”需要更改吗?
-
没有哥们,
onload,<form>没看到。 -
添加name='form1'后,还是不行。
标签: javascript c# asp.net http-post kentico