客户发现响应内容类型为“application / pdf”,但预期为“text / xml”。请求失败,并显示错误消息:

时间:2013-01-05 07:39:40

标签: c# asp.net html-to-pdf

大家好我已经在网络服务http://www.hiqpdf.com/demo/ConvertHtmlToPdf.aspx中编写了这段代码,如下所示

[WebMethod]
    public void convert(string strURL)
    {
        HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
        string url = strURL;
        byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);

        HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

        // let the browser know how to open the PDF document, attachment or inline, and the file name
        HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=ConvertHtmlPart.pdf; size={0}",
                    pdfBuffer.Length.ToString()));

        // write the PDF buffer to HTTP response
        HttpContext.Current.Response.BinaryWrite(pdfBuffer);

        // call End() method of HTTP response to stop ASP.NET page processing
        HttpContext.Current.Response.End();
    }

我在我的项目中添加了这个作为我本地主机的参考,但在尝试转换时我得到一个例外Client found response content type of 'application/pdf', but expected 'text/xml'. The request failed with the error message:可以帮助我。

1 个答案:

答案 0 :(得分:0)

“。ToString()” - 没有必要

is it?