网站提供下载服务时经常需要实现一个强制下载功能(即强制弹出下载对话框),并且文件名保持和用户之前上传时相同。
Content-Disposition
使用 HTTP Header 的 Content-Disposition: attachment 可以实现下载时强制弹出下载对话框。
Content-Disposition: attachment; filename=filename.ext
Content-Type
浏览器对已知类型的文件(如jpg、pdf、txt等)直接在浏览器内打开,我们通过设置http头中的 Content-Type 来改变浏览器认知的文件类型。 这里把Content-Type 设置为octet-stream,也就是二进制文件流。这样浏览器就会直接打开文件,而不是在浏览器内打开。
Content-Type: application/octet-stream
转载自:
原文链接:https://blog.csdn.net/wwd0501/article/details/49891023
举例:
void appweb_sock_response(MprSocket *pSock, char *pResBuf, UINT64 iRespLen
, char *pMimeType, int httpCode, int httpVer, char *pFileName)
{
AppwebVec_T ioVec;
int errCode;
int len, totalLen;
char szHeadBuf[512] = {
0};
printf("appweb_sock_response4DZ 11\n");
if(!pSock