[英]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.