gpt4 book ai didi

javascript - HttpRequestHandler : Sending a pdf file in response

转载 作者:行者123 更新时间:2023-12-03 05:58:09 24 4
gpt4 key购买 nike

我想要服务器一个 pdf 文件而不是 mp3 文件,请帮忙

private HttpRequestHandler mRequestHandler = new HttpRequestHandler()
{

@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
throws HttpException, IOException
{
try{
File file = new File("/mnt/sdcard/Music/song.mp3");
FileEntity body = new FileEntity(file, "audio/mpeg");
response.setHeader("Content-Type", "application/force-download");
response.setHeader("Content-Disposition","attachment; filename=song.mp3");
response.setEntity(body);

}catch(Exception e)
{
e.printStackTrace();
}

}

};

最佳答案

将内容类型更改为 application/pdf

    @Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
throws HttpException, IOException
{
try{
File file = new File("/my/path/file.pdf");
FileEntity body = new FileEntity(file, "application/pdf");
response.setHeader("Content-Type", "application/force-download");
response.setHeader("Content-Disposition","attachment; filename=file.pdf");
response.setEntity(body);

}catch(Exception e)
{
e.printStackTrace();
}

}

};

您可以检查 mime 类型 here

关于javascript - HttpRequestHandler : Sending a pdf file in response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39845827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com