gpt4 book ai didi

json - Grails httpbuilder json响应

转载 作者:行者123 更新时间:2023-12-02 16:00:24 25 4
gpt4 key购买 nike

我的httpbuilder帖子和json的响应处理遇到一些问题

在我的服务范围内,我有:

def jsonDataToPost = '{"accountNumber" : ' + accNo + ',"accountName" : ' + accName + '}'

def http = new HTTPBuilder('https://myurl.com/dataInput')
def jsonResponse
http.auth.basic ('username','password')
http.request(POST, ContentType.JSON) {
headers.'Content-Type' = 'application/json'
body = jsonDataToPost
response.success = { json ->
println("Success")
jsonResponse = json
}
response.failure = { json ->
println("Fail")
jsonResponse = json
}
}

首先由于某种原因,代码实际上跳过了而不是完成,所以我没有得到我想要的jsonReponse,但是我不知道为什么?如果我回复我的response.success / fail,并且我发布了正确的数据,我的json帖子仍然有效,但是我仍然没有收到json

最佳答案

试试这个,

       def requestData = [foo:bar]
http.request(POST, ContentType.JSON) {
headers.'Content-Type' = 'application/json'
body = (requestData as JSON).toString()
response.success = { resp, reader ->
println("Success")
jsonReponse = reader.text
}
response.failure = { resp, reader ->
println("Failed, status: " + resp.status)
jsonReponse = reader.text
}
}

关于json - Grails httpbuilder json响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31788700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com