我尝试将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的片段,可通过点击按钮访问:
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();
}
答案 0 :(得分:0)
以下是您问题的可能解决方案
<body>
<form id='form1' name='form1' method='POST' action='http://localhost'>
<input type='text' id='name' value='form1'>
<input type='text' name='NEW_ITEM["0"]' value='1234-ABC'>
</form>
<script>document.forms.form1.submit()</script>
</body>
答案 1 :(得分:0)
我没有提到我的代码在ascx页面中,我将代码移到了aspx页面,而response.write现在将表单数据发送到外部URL。