如何在 corda api 中使用 post 而不是 put?
How to use post in corda api instaed of put?
**你如何在 corda api 中使用 post?除了使用 put 方法,我们可以使用 post?
就像@PUT 一样,@POST**
有任何选项吗
@PUT
@Path("create-iou")
fun createIOU(@QueryParam("iouValue") iouValue: Int,
@QueryParam("partyName") partyName: CordaX500Name?):
Response {
if (iouValue <= 0 ) {
return Response.status(BAD_REQUEST).entity("Query parameter 'iouValue' must be non-negative.\n").build()
}
if (partyName == null) {
return Response.status(BAD_REQUEST).entity("Query parameter 'partyName' missing or has wrong format.\n").build()
}
val otherParty = rpcOps.wellKnownPartyFromX500Name(partyName) ?:
return Response.status(BAD_REQUEST).entity("Party named $partyName cannot be found.\n").build()
return try {
val signedTx = rpcOps.startTrackedFlow(::Initiator, iouValue, otherParty).returnValue.getOrThrow()
Response.status(CREATED).entity("Transaction id ${signedTx.id} committed to ledger.\n").build()
} catch (ex: Throwable) {
logger.error(ex.message, ex)
Response.status(BAD_REQUEST).entity(ex.message!!).build()
}
}
是的,只需将注释更改为@POST
:
@PUT
@Path("create-iou")
fun createIOU(@QueryParam("iouValue") iouValue: Int,
@QueryParam("partyName") partyName: CordaX500Name?): Response {
...
}
我用过
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("create-iou")
fun createIOU(@FormParam("iouValue") iouValue: Int...
仅将注释更改为 @POST
的解决方案对我不起作用并给了我这个例外:
java.lang.IllegalArgumentException
: Parameter specified as non-null is null
**你如何在 corda api 中使用 post?除了使用 put 方法,我们可以使用 post?
就像@PUT 一样,@POST**
有任何选项吗 @PUT
@Path("create-iou")
fun createIOU(@QueryParam("iouValue") iouValue: Int,
@QueryParam("partyName") partyName: CordaX500Name?):
Response {
if (iouValue <= 0 ) {
return Response.status(BAD_REQUEST).entity("Query parameter 'iouValue' must be non-negative.\n").build()
}
if (partyName == null) {
return Response.status(BAD_REQUEST).entity("Query parameter 'partyName' missing or has wrong format.\n").build()
}
val otherParty = rpcOps.wellKnownPartyFromX500Name(partyName) ?:
return Response.status(BAD_REQUEST).entity("Party named $partyName cannot be found.\n").build()
return try {
val signedTx = rpcOps.startTrackedFlow(::Initiator, iouValue, otherParty).returnValue.getOrThrow()
Response.status(CREATED).entity("Transaction id ${signedTx.id} committed to ledger.\n").build()
} catch (ex: Throwable) {
logger.error(ex.message, ex)
Response.status(BAD_REQUEST).entity(ex.message!!).build()
}
}
是的,只需将注释更改为@POST
:
@PUT
@Path("create-iou")
fun createIOU(@QueryParam("iouValue") iouValue: Int,
@QueryParam("partyName") partyName: CordaX500Name?): Response {
...
}
我用过
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("create-iou")
fun createIOU(@FormParam("iouValue") iouValue: Int...
仅将注释更改为 @POST
的解决方案对我不起作用并给了我这个例外:
java.lang.IllegalArgumentException
: Parameter specified as non-null is null