簡體   English   中英

無法使用HTMLworker連接到遠程服務器

[英]Unable to connect to the remote server with HTMLworker

我正在用C#開發一個Web應用程序,並使用itextsharp.text元素。 我對itextsharp及其課程非常陌生。 請幫助我解決此錯誤: 無法連接到遠程服務器

這是我的代碼和堆棧跟蹤:

public void CreatePDFDocument(string strHtml) 
{
        DirectoryInfo thisFolder = new DirectoryInfo(Server.MapPath("Temp"));
        if (thisFolder.Exists)
        {
            if (File.Exists(Server.MapPath("Temp/test.pdf")))
            {
                File.Delete(Server.MapPath("Temp/test.pdf"));
            }

            thisFolder.Delete();
            thisFolder.Create();
        }
        else
        {
            thisFolder.Create();

        }
        string strFileName =Server.MapPath("Temp/test.pdf");
        // step 1: creation of a document-object
        Document document = new Document();
        // step 2:
        // we create a writer that listens to the document
        PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create));
        StringReader se = new StringReader(strHtml);
        HTMLWorker obj = new HTMLWorker(document);
        document.Open();
        obj.Parse(se); // this line throws error
        document.Close();
        ShowPdf(strFileName);
}

BOLD中的行引發錯誤。

這是堆棧跟蹤:

發生System.Net.WebException

的HResult = -2146233079

消息=無法連接到遠程服務器

來源=系統

StackTrace:位於System.Net.HttpWebRequest.GetResponse()

在iTextSharp.text.Image.GetInstance(Uri url,布爾handleIncorrectImage)

在iTextSharp.text.Image.GetInstance(Uri url)

在iTextSharp.text.Image.GetInstance(字符串文件名)

在iTextSharp.text.html.simpleparser.HTMLWorker.CreateImage(IDictionary)中,位於iTextSharp.text.html.simpleparser.ElementFactory.CreateImage(String src,IDictionary 2 attrs, ChainedProperties chain, IDocListener document, IImageProvider img_provider, Dictionary 2 img_store,String img_baseurl) `2 attrs)

在iTextSharp.text.html.simpleparser.HTMLTagProcessors.HTMLTagProcessor_IMG.StartElement(HTMLWorker worker,字符串標記,IDictionary`2 attrs)

在iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag,IDictionary`2 attrs)處

在iTextSharp.text.xml.simpleparser.SimpleXMLParser.ProcessTag(布爾值開始)

在iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader閱讀器)

在iTextSharp.text.xml.simpleparser.SimpleXMLParser.Parse(ISimpleXMLDocHandler doc,ISimpleXMLDocHandlerComment注釋,TextReader r,布爾html)

在iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader閱讀器)處

在F:\\ New文件夾\\ EMS \\ EMS \\ Payroll \\ PaySlip.aspx.cs:line 88中的Payroll.PaySlip.CreatePDFDocument(String strHtml)

InnerException:System.Net.Sockets.SocketException

的HResult = -2147467259

Message =無法建立連接,因為目標計算機主動拒絕了它127.0.0.1:5510

來源=系統

錯誤碼= 10061

NativeErrorCode = 10061

StackTrace:位於System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)

在System.Net.ServicePoint.ConnectSocketInternal處(布爾connectFailure,Socket s4,Socket s6,Socket&套接字,IPAddress&地址,ConnectSocketState狀態,IAsyncResult asyncResult,Exception&異常)

的InnerException:

不確定是否沒有HTML內容,但這是否適用於您: http : //forums.asp.net/t/1841173.aspx

該頁面的報價:

由於您的html字符串包含指向某些外部服務器的圖像。 而iTextSharp庫正試圖從那些服務器獲取圖像而未能成功,這就是為什么會出現這些錯誤的原因。

嘗試在同一台計算機上訪問來自瀏覽器的圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM