【问题标题】:Karate automatically sets Content-Type header [duplicate]空手道自动设置 Content-Type 标头 [重复]
【发布时间】:2018-12-06 11:46:22
【问题描述】:

美好的一天!在我的负面测试用例中,我必须 PUT 一个没有 Content-Type 标头的请求,以匹配所需的 4xx 状态代码。问题是空手道会自动设置适当的 Content-Type。 例如。当我将 {} 作为请求传递时,它会设置 application/json;字符集=UTF-8 当我通过 '' 作为请求时,它会设置 text/plain; charset=UTF-8

问题是如何发送没有 Content-Type 标头的 PUT 请求?

【问题讨论】:

    标签: web-services testing automated-tests bdd karate


    【解决方案1】:

    您可以使用以下行来传递 Content-Type:

    并且标头 Content-Type = 'application/json; charset=utf-8'

    【讨论】:

      【解决方案2】:

      只需设置* configure charset = null:

      这是文档:https://github.com/intuit/karate#configure

      详细示例见:content-type.feature

      【讨论】:

      • 抱歉,但问题是如何发送没有 Content-Type 标头的 PUT/POST 请求,而不是没有字符集。
      • @firstNamelastName - 抱歉,这不受支持,您能做的最好的事情就是将 Content-Type 设置为空字符串。你是第一个提出这个要求的人——所以如果这对你很重要——请贡献一个补丁,毕竟这是一个开源项目——否则用纯 java 编写这个特定的测试。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2015-05-05
      • 2013-07-22
      • 2021-05-20
      • 1970-01-01
      • 2012-11-02
      • 2011-01-04
      相关资源
      最近更新 更多