I tried to display (or download) a .pdf in a webbrowser with Javascript from a byte array. I built my code from this post:
http://stackoverflow.com/questions/20401006/show-a-pdf-stream-in-a-new-window
I get this error:
ERROR Request URL Too Long HTTP Error 414. The request URL is too long.
My code uses an $ajax call to a VB WebMethod and receive a base64String (.pdf). The .pdf is generated by an SSRS report server.
VB
Public Function testPDF(data As String) As String
Try
Dim strReportUser As String = Bidon.utilisateur
Dim strReportUserPW As String = Bidon.motDePasse
Dim strReportUserDomain As String = Bidon.domaine
Dim sTargetURL As String = "an URL" + data
Dim req As HttpWebRequest = WebRequest.Create(sTargetURL)
req.PreAuthenticate = True
req.Credentials = New System.Net.NetworkCredential(strReportUser, strReportUserPW, strReportUserDomain)
Dim HttpWResp As HttpWebResponse = req.GetResponse()
Dim fStream As Stream = HttpWResp.GetResponseStream()
Dim fileBytes As Byte() = ReadFully(fStream)
Return System.Convert.ToBase64String(fileBytes)
Catch ex As Exception
Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name + "[exception : " + ex.ToString() + "]")
End Try
Return Nothing
End Function
Public Function ReadFully(input As Stream) As Byte()
Using MemoryStream As New MemoryStream()
input.CopyTo(MemoryStream)
Return MemoryStream.ToArray()
End Using
End Function
JS
success: function (reponse) {
var pdfwin = window.open(escape(reponse.d),"Titre","");
}