Grails HTTPBuilder不使用body中的变量

时间:2013-06-14 15:07:59

标签: grails httpbuilder

我正在使用httpbuilder编写一个使用grails进行调用的代码。一切正常,如果我硬编码身体的值,但当我使用变量传递相同,然后它继续给我 -

Unprocessable Entity. Stacktrace follows:
Message: Unprocessable Entity
   Line | Method
->> 636 | defaultFailureHandler in groovyx.net.http.HTTPBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   492 | doRequest             in     ''
|   427 | doRequest . . . . . . in     ''
|   376 | request               in     ''

代码如下 -

    def input = "s3://in_folder/inputFile.mp3"
    def outFile = "outFile.m3u8"
    def http = new HTTPBuilder("https://app.gridserver.com")
    http.request( groovyx.net.http.Method.POST, groovyx.net.http.ContentType.JSON ) { req ->
        uri.path = 'api/v2'
        headers.Accept = 'application/json'
        headers.'Key' = "ssdflkjdf8338fdjsd"
        body = ["input": input,  
            "output":[  "filename": outFile,
                        "format": "mp3",
                ] ]

        response.success = { resp, reader ->
            println "Got response: ${resp}"
        }
    }
}

如果我将变量“input and outFile”替换为实际值,那么它可以正常工作。

1 个答案:

答案 0 :(得分:0)

好吧,我似乎终于解决了它。我需要在表达式中执行.toString(),以便它像文字一样将它转换为json。所以最后我把它写成“s3:// audio_in / $ {fileName} .mp3”.toString(),它运行正常。