首页 > 解决方案 > 如何在空手道中传递 x-www-form-urlencoded - grant_type=client_credentials

问题描述

如何在空手道中传递 x-www-form-urlencoded - grant_type=client_credentials。

你好,

我正在尝试以空手道 x-www-form-urlencoded 的形式传递值 grant_type=client_credentials,这是我与邮递员一起做的。

我知道空手道会将内容类型默认设置为 x-www-form-urlencoded,但是你能帮我在这里做错什么吗?

空手道脚本:

enter code here
  Given url 'http://env/singlesignon/v1/access/token'
 And header Authorization = 'Basic c2JsLWFwaWdlZS1lemJvYi1jbGllbnQ6c2JsLWFwaWdlZGllbnQ='
 And header X-Correlation-Id = 'alibgefh'

 And header X-Consumer = 'APIGEE'

 And form field grant_type = 'client_credentials'

 When method post

 Then status 200

请求标头:

enter code here
 Authorization: Basic c2JsLWFwaWdlZS1lemJvYi1jbGllbnQ6c2JsLWFwaWdlZGllbnQ=
 Connection: Keep-Alive
 Content-Length: 29
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
 X-Consumer: APIGEE
 X-Correlation-Id: alibgefh

回复:

{"error_description":"错误的内容类型","error":"错误的请求"}

标签: karate

解决方案


也许您的服务器不喜欢该charset=UTF-8部件(这是您服务器上的一个错误)。尝试在之前添加此行:

* configure charset = null

否则您的问题中没有足够的数据。如果可能,请与您的服务器端团队中的某个人合作。您可以尝试使用有效的 cURL 命令编辑您的问题,这可能会有所帮助。


推荐阅读