Reputation: 915
I have to use this value as path parameter 6425716f2f8541d5afd52a6e7321743b%2Fv3
It should look like this
GET https://abc123.com/policyNumber/6425716f2f8541d5afd52a6e7321743b%2Fv3
However it is getting changed to 6425716f2f8541d5afd52a6e7321743b%252Fv3 when I do not use encoding. <Changes %2 to %25>
I have tried this approach as well:
* def encoded = 6425716f2f8541d5afd52a6e7321743b%2Fv3
* def id = java.net.URLDecoder.decode(encoded, 'UTF-8')
And path 'abc/v3/policies/'
* header Content-Type = 'application/json'
And path id
However in the above case I get 6425716f2f8541d5afd52a6e7321743b/v3<Removed the %2F and changed to />
I am using version <karate.version>0.9.5</karate.version>
How do I handle this encoding for path parameter?
Upvotes: 1
Views: 604
Reputation: 58058
First we don't support old versions. The rules are explained here: https://github.com/karatelabs/karate#path
I tried this in the latest version (1.3.0)
* def encoded = '6425716f2f8541d5afd52a6e7321743b%2Fv3'
* def id = karate.urlDecode(encoded)
* print id
* url 'https://httpbin.org/anything'
* path id
* method get
Request sent:
1 > GET https://httpbin.org/anything/6425716f2f8541d5afd52a6e7321743b/v3
1 > Host: httpbin.org
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/17.0.4)
1 > Accept-Encoding: gzip,deflate
You can confirm from the server response that it is handled correctly.
You can also try this which seems to work the way you want (but I personally think is not what your server expects)
* def encoded = '6425716f2f8541d5afd52a6e7321743b%2Fv3'
* url 'https://httpbin.org/anything' + '/' + encoded
* method get
Result:
1 > GET https://httpbin.org/anything/6425716f2f8541d5afd52a6e7321743b%2Fv3
Upvotes: 1