使用HTTPCLIENT从代码下载的SSRS PDF报告已损坏

时间:2017-07-13 18:49:17

标签: azure reporting-services virtual-machine

SSRS报告托管在Azure中的虚拟机上,启用了Windows身份验证。我可以通过提供凭据在浏览器中点击URL来下载PDF,但同样不能使用代码。我可以下载PDF但是说它已损坏。 当我点击浏览器中的URL时,下载的PDF大小为900KB,但下载120kb的代码相同,并且说它已损坏。这是否存在下载较少字节的安全问题?

以下是示例代码:

var handler = new HttpClientHandler {Credentials = new NetworkCredential(“username”,“Password”,“domain”)}; HttpClient客户端=新的HttpClient(处理程序); HttpResponseMessage result = client.PostAsync(requestConnection,content).Result; var responseData = result.Content.ReadAsByteArrayAsync()。Result;

1 个答案:

答案 0 :(得分:1)

如果您尝试将SSRS报告导出为PDF,我在这里使用的一些代码会生成一个报告到MemoryStream中,但是如果您想要将其保存到文件中

所有变量结束" VAR"并且是字符串

我希望这可以帮助你

                            Dim ServerUrl As New Uri(ReportServerUrlVAR)
                            Dim ReportViewer1 As New ReportViewer
                            ReportViewer1.ServerReport.ReportServerUrl = ServerUrl
                            ReportViewer1.ServerReport.ReportPath = "/" & ReportsPathNameVAR & "/" & ReportNameVAR
                            ReportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = New Net.NetworkCredential(ReportServiceUserNameVAR, m_Datamanager.Settings.ReportServicePasswordVAR)

                            ReportViewer1.RefreshReport()

                            Dim mimeType As String = String.Empty
                            Dim encoding As String = String.Empty
                            Dim extension As String = String.Empty
                            Dim deviceInfo As String = String.Empty
                            Dim streamids As String() = Nothing
                            Dim warnings As Warning() = Nothing
                            Dim format As String = "PDF"
                            deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
                            Dim bytes As Byte() = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)

                            Dim ms As New MemoryStream(bytes)

                            'Create Email
                            Dim SmtpServer As New SmtpClient
                            Dim mail As New MailMessage
                            If EmailUserNameVAR <> String.Empty Then
                                SmtpServer.Credentials = New Net.NetworkCredential(EmailUserNameVAR, EmailPasswordVAR)
                            End If
                            SmtpServer.Port = EmailServerPortVAR
                            SmtpServer.Host = EmailServerVAR
                            mail = New MailMessage()
                            mail.From = New MailAddress(EmailFromAddressVAR)
                            mail.To.Add(m_EmailAddress)
                            Dim NewAttach As New Attachment(ms, ReportNameVAR & ".pdf")
                            mail.Attachments.Add(NewAttach)
                            mail.Subject = "Automatic Email Report: " & ReportNameVAR
                            mail.Body = "This message is an Automatic Email Report: " & ReportNameVAR & vbCrLf & "Please Check the Attached File."
                            SmtpServer.Send(mail)
                            Application.ExitThread()