POST期间,请求正文中的变量被{}替换

编程入门 行业动态 更新时间:2024-10-28 04:27:13
本文介绍了POST期间,请求正文中的变量被{}替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用空手道DSL(0.6.1.1版),并且遇到以下情况:

I'm using Karate DSL (version 0.6.1.1), and I have the following scenario:

Scenario: Given url baseURL * def email = "test_email@test_domain" * def query = "SELECT * FROM public.users where username='" + email + "' ORDER BY user_id ASC" * def dbUrl = databaseUrl + "databaseName" * def config = { username: '#(databaseUsername)', password: '#(databasePassword)', url: '#(dbUrl)', driverClassName: 'org.postgresql.Driver' } * def DbUtils = Java.type('utility.database.DbUtils') * def db = new DbUtils(config) * def results = db.readRow(query) * def supplierId = results.user_id * print "SUPPLIERID: " + supplierId Given path '/path/to/endpoint' And header content-type = 'application/json' And request { supplierId: #(supplierId) } When method POST Then status 200

utility.database.DbUtils 是一个自定义类,而 readRow()是该类的单行成员,该类返回">代码> JdbcTemplate.queryForMap(query) .

utility.database.DbUtils is a custom class and readRow() is a single line member of that class that returns the result of JdbcTemplate.queryForMap(query).

运行此方案将提供以下日志:

Running this scenario gives the following log:

10:53:17.477 [main] INFO com.intuit.karate - [print] SUPPLIERID: 957750e7-ee6b-486d-977c-05c8ac7bb589 10:53:17.506 [main] INFO com.intuit.karate - request:{ "supplierId": 957750e7-ee6b-486d-977c-05c8ac7bb589 } 10:53:18.372 [main] DEBUG com.intuit.karate - 1 > POST baseurl/path/to/endpoint 1 > Accept-Encoding: gzip,deflate 1 > Connection: Keep-Alive 1 > Content-Length: 17 1 > Content-Type: application/json 1 > Host: base.url 1 > User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_162) {"supplierId":{}}

您可以看到,请求主体首先具有 supplierId 的值,即 957750e7-ee6b-486d-977c-05c8ac7bb589 .不过,一旦完成POST, supplierId 就是 {} .这似乎与 supplierId 由数据库调用填充有关.如果我用简单的 * def providerId ="957750e7-ee6b-486d-977c-05c8ac7bb589" 替换对数据库的调用,则请求正文将按预期显示.

You can see that at first the request body has the value of supplierId as 957750e7-ee6b-486d-977c-05c8ac7bb589. Once the POST is made though, supplierId is just {}. This seems to have something to do with the fact that supplierId is populated by a database call. If I replace the call to the database with a simple * def supplierId = "957750e7-ee6b-486d-977c-05c8ac7bb589", the request body appears as expected.

为什么在进行POST调用时用 {} 替换 supplierId ,如何阻止它执行此操作?

Why is supplierId replaced with {} when the POST call is made, and how do I stop it from doing that?

推荐答案

看起来像是类型转换问题.我通过将 * def providerId = results.user_id 替换为 * string providerId = results.user_id 来使其工作.

Looks like it was a type conversion issue. I got it working by replacing * def supplierId = results.user_id with * string supplierId = results.user_id.

更多推荐

POST期间,请求正文中的变量被{}替换

本文发布于:2023-10-29 07:36:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文中   变量   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!