我想在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