drh19790711 2018-10-25 11:30
浏览 57

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 :)

  • 写回答

1条回答 默认 最新

  • douxi1738 2018-10-25 11:44
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路