繁体   English   中英

我们可以从请求中排除设置http标头Content-type:application / json吗?

[英]Can we exclude setting http header Content-type:application/json from the request?

我正在尝试使用Chrome中的Postman插件创建邮递员收款请求。

请求的预览如下所示:

PUT /api/20130409/system/users/618a9ff389bc4bcda22e20150f818d78 HTTP/1.1
Host: 127.0.0.1:81
Content-Type: application/json
Cache-Control: no-cache

{ "User": { "UserName": "updated1", } }

然后,我从请求中删除了Content-Type标头,并将ServiceStack的DefaultContentType属性设置为“ application / json”。

问题1:

ServiceStack是否应该将请求内容解释为JSON? (在我的盒子上失败)

我的理解是DefaultContentType是关于在请求上设置“ Accept”标头的。 如果请求中没有为“ Accept”标头设置"Application/json""Application/xml"类的特定值,则响应内容将默认为在DefaultContentType属性上设置的值。

如果我的上述理解是正确的...

问题2:

PUT/POST方案中,请求是否总是需要设置适当的Content-Type标头?

我不确定默认的内容类型,但是您可以在主机配置中修改和设置所需的内容类型,请尝试以下操作:

 DefaultContentType = ContentType.Json

您也可以选择xml。

暂无
暂无

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

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