使用JSON的Restlet POST [英] Restlet POST using JSON

查看:264
本文介绍了使用JSON的Restlet POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现接受JSON发布的Restlet函数? 而我该如何使用curl测试呢?

How do I implement Restlet function which accepts JSON post? And how do I test this using curl?

谢谢

推荐答案

使用Restlet 2,您可以:

With Restlet 2, you can either:

  • @Post acceptRepresentation(Representation entity)中测试实体的媒体类型兼容性:

  • test the entity media-type compatibility in @Post acceptRepresentation(Representation entity):

@Post
public Representation acceptRepresentation(Representation entity)
        throws ResourceException {
    if (entity.getMediaType().isCompatible(MediaType.APPLICATION_JSON)) {
       // ...
    }
    // ...
}

  • 或将@Post与一个或两个参数一起使用:

  • or use @Post with one or two parameters:

    @Post("json") Representation acceptAndReturnJson(Representation entity) {
        // ...
    }
    

  • 请参阅以下链接:

    • http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2585586
    • http://www.restlet.org/documentation/2.0/jse/api/org/restlet/resource/Post.html

    (对于Restlet 1,您需要测试实体的类型.)

    (With Restlet 1, you would need to test the type of the entity.)

    这篇关于使用JSON的Restlet POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆