这是我的情景。
val header = Map(
"Accept" -> """application/json""",
"Content-Type" -> """application/x-www-form-urlencoded, charset=UTF-8""")
val auth_token = scenario("POST Authentication")
.exec(
http("POST OAuth Req")
.post("/validate/activationURL")
.formParam("oauth.token.client.secret", "*******")
.formParam("oauth.token.url", "https://myweb.com/as/token.oauth2")
.formParam("oauth.token.client.id", "my-test-user")
.formParam("oauth.token.grant.type", "client_credentials")
.formParam("oauth.token.scope", "my:test:activation")
.headers(header)
)
但是我收到了错误
=========================
HTTP request:
POST https://my-validation.net/validate/activationURL
headers=
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Content-Length: 305
Host: https://my-validation.net/
params=
oauth.token.client.secret: *******
oauth.token.url: https://myweb.com/as/token.oauth2
oauth.token.client.id: my-test-user
oauth.token.grant.type: client_credentials
oauth.token.scope: my:test:activation
=========================
HTTP response:
status=
401 Unauthorized
headers=
Cache-Control: no-store
Content-Type: application/json;charset=UTF-8
Date: Fri, 03 Feb 2017 03:30:40 GMT
Pragma: no-cache
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Www-Authenticate: Bearer realm="oauth2-resource", error="unauthorized", error_description="Full authentication is required to access this resource"
X-Cf-Requestid: 4681a3da-a747-40f7-4801-b6b972b07cf6
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Xss-Protection: 1; mode=block
Content-Length: 102
body=
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
<<<<<<<<<<<<<<<<<<<<<<<<<
20:30:40.972 [DEBUG] i.g.h.a.ResponseProcessor -
>>>>>>>>>>>>>>>>>>>>>>>>>>
答案 0 :(得分:1)
最后,我弄明白了,这个答案在这里帮助了我https://stackoverflow.com/a/41273020/1665592
我改变了什么,
<强>接头强>
是的,标题非常重要。
val header = Map(
"Content-Type" -> """application/x-www-form-urlencoded""")
当我尝试client_secret, client_id, grant_type, scope
oauth.token.client.secret
val auth_token = scenario("POST Authentication")
.exec(
http("POST OAuth Req")
.post("https://myweb.com/as/token.oauth2")
.formParam("client_secret", "*******")
.formParam("client_id", "my-test-user")
.formParam("grant_type", "client_credentials")
.formParam("scope", "my:test:activation")
.headers(header)
.check(status.is(200)).check(jsonPath("$.access_token").exists.saveAs("access_token")