javascript
  • c#
  • html
  • asp.net
  • http
  • 2016-03-04 53 views 1 likes 
    1

    我想在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没有正确触发一样。我错过了什么?

    +0

    此外,我注意到,document.forms是网页上的空白。这可能与为什么表单本身没有提交有关。 – awh112

    回答

    0

    尝试设置这个值

    HttpContext.Current.Response.setContentType("text/html; charset=UTF-8"); 
    

    按照这个答案Html body "onload" is not working in Chrome

    +0

    我不得不稍微修改一下,但这似乎有伎俩。这里是我使用的: 'HttpContext.Current.Response.ContentType =“text/html; charset = UTF-8”;' 感谢您的帮助! – awh112

    相关问题