gpt4 book ai didi

grails - 如何使用grails 3.3.9在RestBuilder的post请求中发送 header

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

Response response = new RestBuilder.post(finalUrl){
header: ["ticket", "getProxyTicket()",
"name", "abc",
"id", "1"
]
contentType: application/json
json data
}

我有上面的代码。当我通过API调用发送发布请求时,出现异常“代理票证必须作为 header 中的参数发送”。我不知道代码有什么问题。谁能帮我?

最佳答案

有不同的方法可以做到这一点。这应该工作:

new RestBuilder().post(finalUrl){
// this will work if you want the value
// of the ticket header to be the literal "getProxyTicket()".
// if you are trying to invoke a method and you want the return
// value of that method to be the header value, remove the double
// quotes around getProxyTicket()
header "ticket", "getProxyTicket()"
header "name", "abc"
header "id", "1"

// no need to set the content type, the
// json method below will do that
// contentType: application/json
json data
}

关于grails - 如何使用grails 3.3.9在RestBuilder的post请求中发送 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58937757/

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