首页 > 解决方案 > 如何在corda api中使用post而不是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()
            }
        }

标签: corda

解决方案


我用了

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("create-iou")
fun createIOU(@FormParam("iouValue") iouValue: Int...

仅将注释更改为的解决方案@POST对我不起作用,并给了我这个例外:

java.lang.IllegalArgumentException: 指定为非空的参数为空


推荐阅读