corda - 如何在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()
}
}
解决方案
我用了
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("create-iou")
fun createIOU(@FormParam("iouValue") iouValue: Int...
仅将注释更改为的解决方案@POST
对我不起作用,并给了我这个例外:
java.lang.IllegalArgumentException
: 指定为非空的参数为空
推荐阅读
- php - 如何在 Laravel 控制器中回显数组的对象名称
- postgresql - 找到重复的键,但表中没有匹配项
- environment-variables - 如何防止本地 msmpi 安装加载系统范围的 msmpi.dll
- standards - 了解 R 中的正态分布和标准单位代码
- javascript - 图表 JS 版本 3 未在引擎 wkhtmltopdf 的 pdf 中显示
- java - 正则表达式在开头和之间没有空格,并且只有一个空格
- .net-core - .Net Core 3.1 身份会话即将到期
- node.js - SearchFilterPipe 的模型具有 id 而不是值(关联)
- mysql - MySQL - TypedQuery 忽略构造函数的空值
- sabre - “意外的请求处理错误”是什么意思以及如何解决?