简体   繁体   English

在POST请求中从正文检索JSON-Java

[英]Retrive JSON from body in a POST request - Java

I'm developing a REST server using RESTlet framework. 我正在使用RESTlet框架开发REST服务器。 I'm in the process of receiving POST requests with a JSON object in the body. 我正在接收正文中带有JSON object POST请求。 But I'm lost on how can I access the JSON object that comes in the POST body. 但是我迷失了如何访问POST正文中的JSON object So I'm asking for some direction here on how to access the body of the POST request. 因此,我在这里要求有关如何访问POST请求的正文的一些指导。

This POST requests will be made by the clients using my server. 客户端将使用我的服务器发出此POST请求。

My server is running on android. 我的服务器在android上运行。

EDIT: 编辑:

My class is extending Restlet , I know how to do it if it was extending ServerResource , but in this case I can't change from extending Restlet to ServerResource 我的课程是扩展Restlet ,如果扩展ServerResource ,我知道该怎么做,但是在这种情况下,我不能从将Restlet扩展为ServerResource

You can simply do something like this in a ServerResource: 您可以在ServerResource中简单地执行以下操作:

@Post
public void yourMethod(Representation rep) {...}

Or... 要么...

If you are extending Restlet and overriding the handle(Request, Response) method or similar then you can call getEntity() on the request to get the Representation . 如果要扩展Restlet并覆盖handle(Request, Response)方法或类似方法,则可以在请求上调用getEntity()以获取Representation

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

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