c# webapi处理请求文件接口返回的Content-Type →textplain

tech2022-12-20  56

c# webapi处理请求文件接口返回的Content-Type →text/plain

通过Header中的Content-Disposition属性获取文件名称和扩展名称HttpWebResponseWebClient 前提是相应的Headers有这个值

通过Header中的Content-Disposition属性获取文件名称和扩展名称

HttpWebResponse

HttpWebResponse response = request.GetResponse() as HttpWebResponse; //文件名称 string filename= response.GetResponseHeader("Content-Disposition"); //文件扩展名称 string exp = filename.Split('.')[1];

WebClient

WebClient client = new WebClient(); //client.DownloadFile(url, saveFilePath + "2." + exp); string filenamewc=client.ResponseHeaders["Content-Disposition"];

前提是相应的Headers有这个值

最新回复(0)