【问题标题】:Multi param values are not replaced properly in the path路径中的多参数值未正确替换
【发布时间】:2018-05-10 10:07:19
【问题描述】:

我在REST调用中有多个参数如下图

/integration/live/rest/accessProfile?page=0&pageSize=10&sortBy=name&fieldList=name,id,date_created,date_modified,created_id,modified_id&filter=id%20not%20equal%20to%20%27200%27%20AND%20id% 20not%20equal%20to%20%27100%27%20AND%20id%20not%20equal%20to%20%27101%27%20AND%20id%20not%20equal%20to%20%27102%27%20AND%20id%20not% 20equal%20to%20%27103%27%20&getTotalRecordCo

我的代码是 * 参数 { page: '0', pageSize: '10',sortBy: 'name', fieldList: ['name','id', 'date_created', 'date_modified', 'created_id', 'modified_id'],filter : 'id%20not%20equal%20to%20%27200%27%20AND%20id%20not%20equal%20to%20%27100%27%20AND%20id%20not%20equal%20to%20%27101%27%20AND% 20id%20not%20equal%20to%20%27102%27%20AND%20id%20not%20equal%20to%20%27103%27%20',getTotalRecordCount:true }

和路径'/integration/live/rest/accessProfile'

当我运行测试用例时,路径没有在 REST 调用中正确替换

运行后发送到服务器的实际调用是

https://vm-trunk-wmic-01.eur.ad.sag/integration/live/rest/accessProfile?page=0&pageSize=10&sortBy=name&fieldList=name&fieldList=id&fieldList=date_created&fieldList=date_modified&fieldList=created_id&fieldList=modified_id&filter=id%2520not%2520equal%2520to%2520%2527200%2527%2520AND%2520id%2520not%2520equal%2520to%2520%2527100%2527%2520AND%2520id%2520not%2520equal%2520to%2520%2527101%2527%2520AND%2520id%2520not%2520equal%2520to%2520%2527102%2527%2520AND%2520id%2520not%2520equal%2520to%2520%2527103%2527%2520&getTotalRecordCount=true

除了路径中的'fieldList'参数外,所有参数都被正确替换。

我正在寻找正确的语法来传递我的以下 REST 调用

/integration/live/rest/accessProfile?page=0&pageSize=10&sortBy=name&fieldList=name,id,date_created,date_modified,created_id,modified_id&filter=id%20not%20equal%20to%20%27200%27%20AND%20id% 20not%20equal%20to%20%27100%27%20AND%20id%20not%20equal%20to%20%27101%27%20AND%20id%20not%20equal%20to%20%27102%27%20AND%20id%20not% 20equal%20to%20%27103%27%20&getTotalRecordCount=true

【问题讨论】:

    标签: karate


    【解决方案1】:

    试试:

    * params { fieldList: 'name,id,date_created,date_modified,created_id,modified_id' }

    编辑:请注意,逗号将根据 HTML 规范进行 URL 编码。如果您真的想“看到”逗号,请自己构建url

    有关执行此操作的 2 种方法的示例,请参阅此提交:https://github.com/intuit/karate/commit/14c6321606bb6bcb626614248f85cc8ea50c61b6

    【讨论】:

    • 嗨,彼得,感谢您的回复。但是建议的解决方案仍然不起作用。在 REST 调用中,逗号 (,) 被替换为 %2Cid%2C。使用建议语法替换的 REST 调用是 fieldList=name%2Cid%2Cdate_created%2Cdate_modified%2Ccreated_id%2Cmodified_id。
    • @Anupama 实际上这是正确的行为:w3schools.com/tags/ref_urlencode.asp - 您的服务器应该能够正确解码参数。如果服务器无法调试 - 这是服务器端的错误。如果你真的坚持在 URL 中看到逗号,你有一个解决方法 - 使用 URL,查看我的编辑
    • 嗨彼得,正如你所说,这是服务器端的错误。正如您建议的解决方法 - 'url 中的参数' 工作得非常好。谢谢 :) 工作代码是 Given url appServer +'/integration/live/rest/accessProfile'+'?page=0'+'&pageSize=10'+'&sortBy=name'+'&fieldList=name,id,date_created, date_modified,created_id,modified_id'+'&filter=id%20not%20equal%20to%20%27200%27%20AND%20id%20not%20equal%20to%20%27100%27%20AND%20id%20not%20equal%20to% 20%27101%27%20AND%20id%20not%20equal%20to%20%27102%27%20AND%20id%20not%20equal%20to%20%27103%27%20'+'&getTotalRecordCount=true' 003ms
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多