【问题标题】:Complete page html via c# or jquery ajax通过 c# 或 jquery ajax 完成页面 html
【发布时间】:2013-10-09 16:10:07
【问题描述】:

有没有办法用 Asp.net、Jquery 和 Ajax 来捕获当前页面 html 并通过电子邮件发送或保存它。我有一个包含动态生成的输入量的页面,并且有很多。我想做的只是在填写完表单后捕获完整的 html 并通过电子邮件发送。有没有办法做到这一点。我有一个 web 服务,它通过 ajax 传递数据,但是在处理大于和小于符号和引号等时遇到了问题。关键是对他们在屏幕上键入的任何内容都有一个可读的副本。 html 电子邮件是客户想要的方式。谢谢!

这也可以直接在后面的代码中,但我找不到在客户端不回发的情况下执行服务器端的方法。

我在 firebug 中收到的错误是“消息”:“传入的对象无效,\u0027:\u0027 或 \u0027}\u0027 应为。

【问题讨论】:

    标签: jquery html asp.net ajax


    【解决方案1】:

    处理大于和小于符号时出现问题 和引号等。

    您应该尝试HttpUtility.HtmlDecode 以解决该问题。

    剩下的,你应该试试这个 (source):

    private void SaveWebPage_as_HTML()
    {
        // Initialize the WebRequest.
        string urlToConvert = (System.Web.HttpContext.Current.Request.Url).ToStr ing();
        WebRequest myRequest = WebRequest.Create(urlToConvert);
        // Return the response. 
        WebResponse myResponse = myRequest.GetResponse();
    
        // Obtain a 'Stream' object associated with the response object.
        Stream ReceiveStream = myResponse.GetResponseStream();
        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
    
        // Pipe the stream to a higher level stream reader with the required encoding format. 
        StreamReader readStream = new StreamReader(ReceiveStream, encode, true, 255);
    
        // Read 256 charcters at a time. 
        Char[] read = new Char[256];
        int count = readStream.Read(read, 0, 256);
        using (StreamWriter sw = new StreamWriter("output.html"))
        {
            while (count > 0)
            {
            // Dump the 256 characters on a string and display the string onto the console.
            String str = new String(read, 0, count);
            sw.Write(str);
            count = readStream.Read(read, 0, 256);
            }
        }
    
        // Close the response to free resources.
        myResponse.Close();
    }
    

    密切注意使用的编码(这里是 utf-8),因为这可能会导致“可读性”问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 2014-10-10
      • 2017-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2016-02-01
      相关资源
      最近更新 更多