使用c#从jasperserver下载PDF报告

时间:2016-12-12 12:28:17

标签: c# jasperserver

我正在尝试从我的jasperserver下载pdf

这是演示代码:

   public void Genrate_Report_By_ID(String report_id )
    {

    String Server_Adress = "http://localhost:8081/jasperserver-pro";
        try
        {

            // Setup WebClient 
            WebClient httpclient = new WebClient();

            //Basic Auth
            httpclient.Credentials = new NetworkCredential("superuser", "superuser");
            httpclient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");


            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Server_Adress+"/rest/resource/organizations/M/Report_By_ID");
            request.Method = "GET";
            string requestXml = String.Empty;
            request.Credentials = httpclient.Credentials;
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                requestXml = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
            }


            // Send PUT
            string requestAllResult = "";
            requestAllResult = httpclient.UploadString(Server_Adress + "/rest/report/organizations/M/Report_By_ID?RUN_OUTPUT_FORMAT=PDF", "PUT", requestXml);

            // Get session cookie
            string session = httpclient.ResponseHeaders.Get("Set-Cookie");
            // Set session cookie
            httpclient.Headers.Add("Cookie", session);

            // Extract uuid, filename is always report
            XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(requestAllResult);
            XmlNode node = doc.DocumentElement.SelectSingleNode("uuid");
            string uuid = node.InnerText;

            //Build GET URL
            string reportUrl = Server_Adress + "/rest/report/";
            reportUrl += uuid;
            reportUrl += "?file=report";


         }
        catch (Exception ex)
        {

            throw ex;
        }


    }

但是这个例外发生了。

  

System.Net.WebException:底层连接已关闭:接收时发生意外错误。 ---> System.IO.IOException:无法从传输连接读取数据:远程主机强行关闭现有连接。

凭证是正确的。

0 个答案:

没有答案