Gre*_*egg 5 rest grails grails-plugin httpbuilder
最新版本的Grails REST客户端插件:
withHttp(uri: "http://foo/bar") {
def bodyContent = [
apiKey: "somekey",
identifier: identity.identity,
activity: ac as JSON
]
def json = post(path: 'activity', body: bodyContent)
if (json.stat == 'ok') {
wsr.success = true
}
}
Run Code Online (Sandbox Code Playgroud)
如何向此请求添加标头数据?
您应该能够将Closure传递给post方法并在那里设置标头.
withHttp(uri: "http://foo/bar") {
def bodyContent = [
apiKey: "somekey",
identifier: identity.identity,
activity: ac as JSON
]
def json = post(path: 'activity', body: bodyContent) {
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
}
if (json.stat == 'ok') {
wsr.success = true
}
}
Run Code Online (Sandbox Code Playgroud)
以下也应该有效:
....
....
def json = post(path: 'activity',
body: bodyContent,
headers:['User-Agent':'myagent'])
....
....
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3626 次 |
| 最近记录: |