ANDROID:意图在浏览器下载fpdf下载php文件而不是pdf生成

Good day!

I have a function in my mobile application which in a click of a button makes an intent of :

                Intent I = new Intent(Intent.ACTION_VIEW);
                I.setData(Uri.parse(URL));
                CONTEXT.startActivity(I);

With the URL as https://mydomain.xyz/outputs/grades/index.php?ID=1000

However it just downloads the index.php file itself rather than the generated pdf file using the fpdf library (from: http://www.fpdf.org/).

I tried opening the link directly from a browser and it downloaded the generated pdf file.

I am just a student creating an app for a school project so I am not that well versed in this things so I am very thankful for all the help :)

you need to set the correct HTTP headers for your request, specifically: Content-Type and Content-Disposition.

Content-Type will tell the server what content the client is expecting: Content-Type: application/pdf will let the server know that the expected content is of type PDF.

Content-Disposition: attachment; filename="filename.jpg" to specify the response should be a download and not displayed in a browser or anything.