简体   繁体   English

如何在OpenRasta中设置Content-Type标头字符集

[英]How to set Content-Type header charset in OpenRasta

When I return my object as JSON via JsonDataContractCodec OpenRasta sets Content-Type header to 当我通过JsonDataContractCodec以JSON格式返回对象时,OpenRasta将Content-Type标头设置为

application/json 应用程序/ json

but ignores charset part of content type. 但忽略内容类型的字符集部分。

When I use Chrome it sends GET request with folowing header: 当我使用Chrome时,它发送带有以下标头的GET请求:

Accept-Charset:windows-1251,utf-8;q=0.7,*;q=0.3 接受字符集:windows-1251,utf-8; q = 0.7,*; q = 0.3

and all my utf-8 encoded json objects goes wrong. 而且我所有utf-8编码的json对象都出错了。

I tried to override OperationResult with no luck. 我没有运气就试图覆盖OperationResult。 OpenRasta overwrites my header with codec's one. OpenRasta用编解码器的头覆盖了我的头。

Just found a way - inherit from JsonCoder and apply the MediaTypeAttribute : 刚刚找到了一种方法-从JsonCoder继承并应用MediaTypeAttribute

[MediaType("application/json; charset=utf8")]
public class JsonWithEncoding:JsonDataContractCodec
{

}

And register handler with: 并使用以下命令注册处理程序:

ResourceSpace.Has
  .ResourcesOfType<IEnumerable<ProfileResource>>()
  .AtUri("/profiles")
  .HandledBy<ProfileHandler>()
  .TranscodedBy<JsonWithEncoding>();

But this way is very static:( 但是这种方式非常静态:(

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM