我正在尝试使用RESTClient类来发布RESTful Web服务。我在groovyx.net.http.HTTPBuilder $ RequestConfigDelegate的setBody上获得了一个NPE。
我的代码是
postParam = [
sourceAccountNo : fundTransfer.fromAccount.accountNumber,
sourceBankCode : fundTransfer.fromAccount.bank.bankCode,
destinationBankCode : fundTransfer.toAccount.bank.bankCode,
destinationBankAccountNo: fundTransfer.toAccount.accountNumber,
amount : fundTransfer.amount,
narrationOne : fundTransfer.note,
uniqueId : fundTransfer.uniqueId
]
String balanceTransferURL = ApplicationProperty.propertiesMap.get(ApplicationProperty.PropertyKey.BULK_BALANCE_TRANSFER_URL)
def restClient = new RESTClient(balanceTransferURL)
def restResponse = restClient.post(requestContentType:JSON,body:postParam)
我的错误日志如下
message: null
Line | Method
->> 1200 | setBody in groovyx.net.http.HTTPBuilder$RequestConfigDelegate
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1111 | setPropertiesFromMap in ''
| 946 | <init> . . . . . . . . . . in ''
| 140 | post in groovyx.net.http.RESTClient
究竟缺少什么?我做错了什么?
答案 0 :(得分:0)
我遇到了同样的问题并发现当你添加requestContentType参数时它会消失:
import static groovyx.net.http.ContentType.JSON
requestContentType:JSON