I am trying to download pdf from my jasperserver
here is the demo code :
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;
}
}
But this Exception occurs .
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Credential are correct .