ok, I seems to have solved it finally. I needed to do the .toString() in the expression so that it takes it like a literal and dont convert it into a json. so finally I wrote it like "s3://audio_in/${fileName}.mp3".toString() and it works fine.
Grails HTTPBuilder not working with variable in body
-
31-05-2022 - |
题
I am writing a code in grails which is making a post call using httpbuilder. everything works fine if I hardcode the values for body but when I pass the same using variables, then it keep giving me -
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 ''
The code is like below -
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}"
}
}
}
If I replace the variables "input and outFile" here with the actual value then it works fine.
解决方案
不隶属于 StackOverflow