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

How to send header in post request of RestBuilder using grails 3.3.9

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

我有上面的代码。当我通过 API 调用发送 post 请求时,我得到一个异常 "Proxy ticket must be sent as parameter in 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
}