You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Karate至1.1.0/1.2.0后,Multipart带JSON的POST请求返回400求助

Karate版本升级后Multipart POST请求返回400错误求助

原在Karate 0.9.6版本中可正常发送包含JSON值的Multipart POST请求,升级至1.1.0后出现400错误。升级到1.2.0并尝试对应解决方案后问题仍未解决。以下是两种请求代码示例、输入JSON内容及400响应信息,寻求解决办法:

代码示例1

Given path apiURL
* def jfile = read(input_json)
And multipart file jsondata = { value: '#(jfile)'}
And header Content-Type = 'multipart/form-data'
When method post
Then status 200

输入JSON内容

{
    "cake": {
        "topping": "none",
        "batter": [
            {
                "id": "1001",
                "type": "Regular"
            },
            {
                "id": "1002",
                "type": "Chocolate"
            }
        ]
    }
}

代码示例1的400响应信息

1 < 400
1 < Expires: 0
1 < Cache-Control: no-cache, no-store, max-age=0, must-revalidate
1 < X-Powered-By: xxx
1 < Server: xxx
1 < X-XSS-Protection: 1; mode=block
1 < Pragma: no-cache
1 < X-Frame-Options: DENY
1 < Date: Tue, 27 Sep 2022 14:41:11 GMT
1 < Connection: keep-alive
1 < X-Content-Type-Options: nosniff
1 < Transfer-Encoding: chunked
1 < Set-Cookie: JSESSIONID=abc; Domain=localhost

代码示例2

Given path apiURL
* def jfile = read(input_json)
And multipart fields jfile
And header Content-Type = 'multipart/form-data'
When method post
Then status 200

代码示例2的400响应信息

1 < 400
1 < Expires: 0
1 < Cache-Control: no-cache, no-store, max-age=0, must-revalidate
1 < X-Powered-By: xxx
1 < Server: xxx
1 < X-XSS-Protection: 1; mode=block
1 < Pragma: no-cache
1 < X-Frame-Options: DENY
1 < Date: Tue, 27 Sep 2022 15:07:34 GMT
1 < Connection: keep-alive
1 < X-Content-Type-Options: nosniff
1 < Transfer-Encoding: chunked
1 < Set-Cookie: JSESSIONID=abc; Domain=localhost

内容的提问来源于stack exchange,提问作者Badhri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 05:30:43