如何在 POST 请求 hyperledger composer rest 服务器中为参数提供空值
How to give empty value for argument in POST request for hyperledger composer rest server
我正在尝试通过 R 使用 httr 包向 composer rest 服务器发出 post 请求。我写了一段代码,然后从中创建了 composer rest 服务器。这些是我的详细信息
请求URL:http://localhost:3000/api/nl.amis.registry.fruits
Body: {
"$class": "nl.amis.registry.fruits",
"Id": "9",
"name": "orange",
"description": "string",
"count": ""
}
首先,我尝试使用 composer rest 服务器。出于我的目的,我需要计数为空,并且该值将由另一个 API 调用附加。我能够通过 count: "" 成功完成交易。我能够在 composer playground 的测试部分中检查这一点。其余代码工作正常,稍后会附加 count 变量。
现在我正在编写一个 R 代码来通过 POST 请求进行类似的交易。在这里,我遇到了 "count cannot be blank" 和 returns 错误 422 Unprocessable entity。我使用的内容类型是application/json。使用 "count":{} 时,post 请求处理正常,我得到 "count":[object Object] 在响应中。但是稍后执行附加的代码将执行类似 count:"[object Object],1" 的操作,其中我期望 "count":"1 “。在 composer playground 中使用测试时一切正常,但在尝试通过 rest API 进行外部访问时却产生了问题。请帮忙。
您可以使用 Optional
关键字在模型文件的资源中声明 count
。使用 Optional
关键字,您可以 post 空值 count
。
for example:
asset fruits identified by Id {
o String Id
o String name
o String description
o String count optional
}
我正在尝试通过 R 使用 httr 包向 composer rest 服务器发出 post 请求。我写了一段代码,然后从中创建了 composer rest 服务器。这些是我的详细信息
请求URL:http://localhost:3000/api/nl.amis.registry.fruits
Body: {
"$class": "nl.amis.registry.fruits",
"Id": "9",
"name": "orange",
"description": "string",
"count": ""
}
首先,我尝试使用 composer rest 服务器。出于我的目的,我需要计数为空,并且该值将由另一个 API 调用附加。我能够通过 count: "" 成功完成交易。我能够在 composer playground 的测试部分中检查这一点。其余代码工作正常,稍后会附加 count 变量。
现在我正在编写一个 R 代码来通过 POST 请求进行类似的交易。在这里,我遇到了 "count cannot be blank" 和 returns 错误 422 Unprocessable entity。我使用的内容类型是application/json。使用 "count":{} 时,post 请求处理正常,我得到 "count":[object Object] 在响应中。但是稍后执行附加的代码将执行类似 count:"[object Object],1" 的操作,其中我期望 "count":"1 “。在 composer playground 中使用测试时一切正常,但在尝试通过 rest API 进行外部访问时却产生了问题。请帮忙。
您可以使用 Optional
关键字在模型文件的资源中声明 count
。使用 Optional
关键字,您可以 post 空值 count
。
for example:
asset fruits identified by Id {
o String Id
o String name
o String description
o String count optional
}