Call to java script code returning the ASCII encoding for ':' separating key and value of returned object

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:06:19

问题


I making an api request using karate where one of the api request params takes a filter condition (which is a java script object).

I am using a literal notation to create a java script object as shown below. This code is in a separate filter.js file.

function() {

var params = {
    val1:[],
    val2:[]
};
return params;

}

Now i call the above .js file in the karate scenario as below:

 Scenario: Test
Given path 'filtertest/'
* param filter = call read('classpath:feature/common/filter/filter.js')
When method get

Ran the above and when i check the log, the api throws bad request error. I looked at the request url and there i can see that the ':' in the js file where I am assigning a value to a object key is replaced with %3A which i believe is the ASCII encoding for ':'. (the param with its values below)

?filter=%7B%22val1%22%3A%5B%5D%2C%22val2%22%3A%5B%5D

What I want is the ':' to come as it is from the .js call as the server side expects the filter param values as key value pairs.

Is there a way I can achieve this?


回答1:


If your server cannot decode an encoded : it is a bug: https://www.w3schools.com/tags/ref_urlencode.asp

If you really need this - the workaround is to use the url keyword and build it manually, path and param will always encode.

Given url baseUrl + '/filtertest?filter=foo:bar'


来源:https://stackoverflow.com/questions/55350262/call-to-java-script-code-returning-the-ascii-encoding-for-separating-key-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!