0
我試圖從我的grails項目中使用web服務。我使用的是httpbuilder 0.7.2。以下是我的http客戶端。Groovy httpbuilder發佈列表params
static def webServiceRequest(String baseUrl, String path, def data,method=Method.GET,contentType=ContentType.JSON){
def ret = null
def http = new HTTPBuilder(baseUrl)
http.request(method, contentType) {
uri.path = path
requestContentType = ContentType.URLENC
if(method==Method.GET)
uri.query = data
else
body = data
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp, json ->
println "response status: ${resp.statusLine}"
ret = json
println '--------------------'
}
}
return ret
}
問題來了,當我試圖發送這樣的事情:
def input = [:]
input['indexArray'] = [1,5]
API調用
def response = webServiceRequest(url,uri,input,Method.POST)
當我打印後數據的價值我服務器它只顯示列表的最後一個值。
{ 「indexArray」: 「5」}
應該同時顯示1和5
爲什麼使用ContentType.URLENC而不是ContentType.JSON?沒有這個, –
服務器沒有收到任何東西 –