OpenRasta POST 操作的正文格式选项
给定 OpenRasta 的以下代码和配置:
ResourceSpace.Has.ResourcesOfType<Foo>()
.AtUri("/foo/{fooID}")
.And.AtUri("/foo")
.HandledBy<FooHandler>()
.AsJsonDataContract();
public OperationResult GetFoo(int fooID) { }
public OperationResult PostFoo(Foo foo) { }
public class Foo
{
public int ID { get; set; }
public string Name { get; set; }
}
如果我想发布到 FooHandler 上的 PostFoo 方法,请求正文的正确格式是什么。它可以是 json (即与我从 GetFoo 收到的格式相同)还是应该是名称-值对(例如 ID=1&Name=FooManChu)?
我是否需要在发布请求中设置任何其他标头(例如内容类型)?
我正在尝试执行此操作,但当我尝试执行此操作时似乎收到 415 错误?
Given the following code and config for OpenRasta :
ResourceSpace.Has.ResourcesOfType<Foo>()
.AtUri("/foo/{fooID}")
.And.AtUri("/foo")
.HandledBy<FooHandler>()
.AsJsonDataContract();
public OperationResult GetFoo(int fooID) { }
public OperationResult PostFoo(Foo foo) { }
public class Foo
{
public int ID { get; set; }
public string Name { get; set; }
}
What is the correct format for the body of the request if I want to post to the PostFoo method on my FooHandler. Can it be json (i.e. the same format I would recieve from GetFoo) or should it be name-value pairs (e.g. ID=1&Name=FooManChu) ?
Do I need to set any additional headers in the post request such as content type ?
I am trying to get this working but I seem to be getting 415 errors when I try to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发送 application/json 的 Content-Type,那就可以了。如果您想使用键值对,使用 multipart/form-data 或 application/x-www-form-urlencoded 那么这也可以。
如果您不指定 Content-Type,则默认为 application/octet-stream,您只有 Stream (和 byte[])的映射。
If you send a Content-Type of application/json, that'll work. If you want to use key value pairs, using either multipart/form-data or application/x-www-form-urlencoded then that'll work too.
If you don't specify Content-Type, it defaults to application/octet-stream, for which you only have a mapping to Stream (and byte[]).