这可能吗?我的 ajax 调用如下所示:
$.ajax( {
type: "POST",
url: "/reporter/api/image/getimage/",
data: { "": httpNonAccessibleFilePath },
success: function ( imageData ) {
$( "#imagecontent" ).append( '<img src="' + imageData + '" />' );
}
} );
在我的 Web.API 方面:
[HttpPost]
public HttpResponseMessage GetImage([FromBody]string serverPath)
{
HttpResponseMessage response = new HttpResponseMessage();
if (serverPath != null)
{
FileInfo fileInfo = new FileInfo(serverPath);
if (fileInfo.Exists)
{
response.Content = new StreamContent( fileInfo.OpenRead() );
response.Content.Headers.ContentType = new MediaTypeHeaderValue( "image/png" );
}
}
return response;
}
所有位都连接好,即我可以点击服务并返回数据......但我没有看到任何图像。我在这里想念什么?