简体   繁体   English

ServiceStack XDomainRequest和缺少Content-Type标头

[英]ServiceStack XDomainRequest and Missing Content-Type header

When I make a XDomainRequest on IE8/9 the Content-Type is not set, in fact Content-Type is missing from the HTTP Header. 当我在IE8 / 9上执行XDomainRequest时,未设置Content-Type,实际上HTTP标头中缺少Content-Type。 This is how IE XDomainRequest works. 这就是IE XDomainRequest的工作方式。

On the backend, how do I tell Servicestack to treat all incoming requests that do not have a Content - Type as application/Json 在后端,如何告诉Servicestack将所有没有Content-Type的传入请求视为application / Json

Thanks 谢谢

Jay 松鸦

You could add a PreRequestFilter in your AppHost that modifies the underlying Request ContentType for your Host, eg: 您可以在AppHost中添加PreRequestFilter,以修改主机的基础Request ContentType,例如:

this.PreRequestFilters.Add((req, res) =>
{
    if (string.IsNullOrWhiteSpace(req.ContentType))
    {
        ((AspNetRequest)req).HttpRequest.ContentType = MimeTypes.Json;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 限制ServiceStack中自定义内容类型的元数据 - Restrict Metadata for Custom Content-Type in ServiceStack 如何使用服务堆栈序列化程序将默认内容类型设置为 Json - How to set default content-type to Json with servicestack serializer Content-Type必须为'application / json-patch + json'JsonServiceClient ServiceStack - Content-Type must be 'application/json-patch+json' JsonServiceClient ServiceStack 如何获得ServiceStack的Swagger实现以使用XML内容类型? - How can I get ServiceStack's Swagger implementation to use XML content-type? 我们可以从请求中排除设置http标头Content-type:application / json吗? - Can we exclude setting http header Content-type:application/json from the request? ServiceStack 4:无法为静态内容添加Expires Header - ServiceStack 4: not able to add Expires Header for static content 解析ServiceStack服务并定义内容类型 - Resolving a ServiceStack Service and defining content type 返回带有html扩展名的文件时Servicestack返回错误的内容类型 - Servicestack return wrong content type when returning a file with html extension 是否可以或必须设置ServiceStack客户端删除请求的内容类型? - Is it possible or necessary to set the content type of a ServiceStack client delete request? ServiceStack“会话”丢失了吗? - ServiceStack 'session' missing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM