Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 客户端发现响应内容类型为';应用程序/pdf';,但预期';text/xml';。请求失败,出现错误消息:_C#_Asp.net_Html To Pdf - Fatal编程技术网

C# 客户端发现响应内容类型为';应用程序/pdf';,但预期';text/xml';。请求失败,出现错误消息:

C# 客户端发现响应内容类型为';应用程序/pdf';,但预期';text/xml';。请求失败,出现错误消息:,c#,asp.net,html-to-pdf,C#,Asp.net,Html To Pdf,大家好,我在web服务中编写了以下代码 [WebMethod] public void convert(string strURL) { HtmlToPdf htmlToPdfConverter = new HtmlToPdf(); string url = strURL; byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url); HttpCont

大家好,我在web服务中编写了以下代码

[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();
    }
我在本地主机的项目中添加了这个作为引用,但当尝试转换时,我得到了一个异常,因为
客户端发现响应内容类型为“application/pdf”,但预期为“text/xml”。请求失败,错误消息为:
有人能帮我吗。

“.ToString()”-不需要


尝试从标题中删除大小
HttpContext.Current.Response.AddHeader(“内容处置”,“附件;文件名=ConvertHtmlPart.pdf”)未工作
SearchAndResQ
在哪里引发此异常?在哪一条线上?我怀疑它在这行:byte[]pdfBuffer=htmlToPdfConverter.ConvertUrlToMemory(url)<响应结束并返回到`obj.convert(txtUrl.Text.ToString());`出现异常我想这是
HttpContext.Current.Response.End()导致异常