我想在C#中编写一个HttpModule,它生成一个空的POST请求到某个URL。我使用了以下代码,我从另一个帖子中获得:HTTP POST在Chrome中自动提交
HttpContext.Current.Response.Clear();
StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>", HttpContext.Current.Request.Url.ToString());
sb.AppendFormat("<input value='submit' type='submit'/>");
//sb.AppendFormat("<input type='hidden' name='id' value='{0}'>", 1);
// Other params go here
sb.Append("</form>");
sb.Append("</body>");
sb.Append("</html>");
HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.End();
在IE中,这可以正常工作。但是,在Chrome中,我只能看到生成的标记,就像body onload没有正确触发一样。我错过了什么?
此外,我注意到,document.forms是网页上的空白。这可能与为什么表单本身没有提交有关。 – awh112