Noe*_*Yap 12 groovy basic-authentication httpbuilder
以下代码不对用户进行身份验证(不会发生身份验证失败,但由于缺少权限而导致调用失败):
def remote = new HTTPBuilder("http://example.com")
remote.auth.basic('username', 'password')
remote.request(POST) { req ->
uri.path = "/do-something"
uri.query = ['with': "data"]
response.success = { resp, json ->
json ?: [:]
}
}
Run Code Online (Sandbox Code Playgroud)
但以下工作正常:
def remote = new HTTPBuilder("http://example.com")
remote.request(POST) { req ->
uri.path = "/do-something"
uri.query = ['with': "data"]
headers.'Authorization' =
"Basic ${"username:password".bytes.encodeBase64().toString()}"
response.success = { resp, json ->
json ?: [:]
}
}
Run Code Online (Sandbox Code Playgroud)
为什么不是第一个工作?
| 归档时间: |
|
| 查看次数: |
14430 次 |
| 最近记录: |