Save pdf from response


#1

Hi guys! How can I generate a PDF file from response returned on http request?
I found this solution,

var uri = android.net.Uri.parse(“http://”+appSettings.getString(“ip”)+":8181/rest/cotizador/obtenerPdf?cotId="+data.cotId);
var downloadManager = application.android.foregroundActivity.getSystemService(“download”);
var request = new android.app.DownloadManager.Request(uri);
request.setDestinationInExternalFilesDir(application.android.context, android.os.Environment.DIRECTORY_DOWNLOADS, fileName);
request.setNotificationVisibility(android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadManager.enqueue(request);

but I can’t use it because my request needs authentication.
This is what I receive from response:

%PDF-1.4
%����
1 0 obj
<</Filter/FlateDecode/Length 29>>stream
x�+�r
�26S075S I�r
�� ��1b 1
endstream
endobj
3 0 obj
<</Tabs/S/Group<</S/Transparency/Type/Group/CS/DeviceRGB>>/Contents 1 0 R/Type/Page/Resources<</ColorSpace<</CS/DeviceRGB>>/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]>>/Parent 2 0 R/MediaBox[0 0 612 792]>>
endobj
2 0 obj
<</Kids[3 0 R]/Type/Pages/Count 1/ITXT(2.1.7)>>
endobj
4 0 obj
<</Type/Catalog/Pages 2 0 R/ViewerPreferences<</PrintScaling/AppDefault>>>>
endobj
5 0 obj
<</ModDate(D:20170622102832-06’00’)/Creator(JasperReports Library version 6.1.0)/CreationDate(D:20170622102832-06’00’)/Producer(iText 2.1.7 by 1T3XT)>>
endobj
xref
0 6
0000000000 65535 f
0000000015 00000 n
0000000333 00000 n
0000000110 00000 n
0000000396 00000 n
0000000487 00000 n
<</Info 5 0 R/ID [<19c3a91b7727a25cc32c6c66fa6ed84d>]/Root 4 0 R/Size 6>>
654
%%EOF

How create a pdf file with this or there’s another solution for this?