客户端发现响应内容类型为'application/pdf',但预期为'text/xml'

本文关键字:xml text pdf application 类型 响应 发现 客户端 | 更新日期: 2023-09-27 17:50:54

大家好,我在web-service 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:可以有人帮助我。

客户端发现响应内容类型为'application/pdf',但预期为'text/xml'

".ToString()"-没有必要

?