请求中的Content-Type ='application / x-www-form-urlencoded'更改为Content-Type:application / json;在空手道版本0.9.2中

时间:2019-05-03 15:15:30

标签: karate

当我发送Content-Type ='application / x-www-form-urlencoded'作为标头时,它更改为Content-Type:application / json;在空手道版本0.9.2中。 在空手道版本0.7.0中,它仅作为Content-Type ='application / x-www-form-urlencoded'发送。

    Given url "https://foo.bar.buzz"
    And header Content-Type = 'application/x-www-form-urlencoded'
    And form field username = "check"
    And form field password = "Password"
    And request {}
    And header Content-Type = 'application/json'
    When method POST
    Then status 200

1 个答案:

答案 0 :(得分:1)

在最后3行中,您设置了header吗?

而且您永远不要使用request正文来提交表单。

尝试以下方法,效果很好:

Given url 'https://postman-echo.com/post'
And form field foo = 'bar'
When method post

结果:

1 > POST https://postman-echo.com/post
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 7
1 > Content-Type: application/x-www-form-urlencoded; charset=UTF-8
1 > Host: postman-echo.com
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_112)
foo=bar