我想从 api
apicontroller 下载客户端文件:
public HttpResponseMessage PostOfficeSupplies()
{
string csv = string.Format ("D:\\Others\\Images/file.png");
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StringContent(csv);
result.Content.Headers.ContentType = new MediaTypeHeaderValue ("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "file.png";
return result;
}
1.如何从api控制器弹出下载jquery(octet-stream)?
my client side code:
$(document).ready(function () {
$.ajax(
{
url: 'api/MyAPI'
, type: "post"
, contentType: "application/octet-stream"
, data: ''
, success:
function (retData) {
$("body").append("<iframe src='" + retData + "' style='display: none;' ></iframe>");
}
});
});
但这行不通!