【发布时间】:2015-02-21 10:32:19
【问题描述】:
我使用以下方法创建一个 HttpResponseMessage 对象并通过我的 Web API 项目返回它:
public HttpResponseMessage CreateHttpResponseMessage(string message, HttpStatusCode httpStatusCode)
{
var stringContent = new StringContent(message, new UTF8Encoding(), "application/javascript");
return new HttpResponseMessage(httpStatusCode)
{
Content = stringContent
};
}
我正在使用它来返回一个 jsonp 有效负载,但它一直以内容类型 text/plain 而不是 application/javascript 返回。这导致浏览器控制台记录此警告:
资源解释为脚本但以 MIME 类型 text/plain 传输
我返回的消息不是 null 或空的,因此我很困惑它为什么会这样。
【问题讨论】:
标签: c# .net asp.net-web-api jsonp