2

I need to send a GET request. One of the parameters has URL query characters in it (e.g., ?, &, and =). How do I URI-encode that in KRL before sending the request?

Here's the pseudocoded idea:

params = "key=value&key=value";
encoded_params = params.urlencode();
request = datasource:service("?data=#{encoded_params}");
4

2 回答 2

2

调用数据源时可以传递字符串或结构。当您使用散列时,散列值由平台自动编码 URL。

你上面的代码会这样写:

rparams = {
  "key1": "value1",
  "key2": "value2"
};
request = datasource:service(rparams);

达达!魔法。

请注意,我在哈希声明中使用了字符串文字,但它们可以是任何表达式,并且这些值将作为数据源请求中的参数传递。

于 2011-04-10T00:20:04.180 回答
1

另请参阅http://docs.kynetx.com/docs/URI

escaped = uri:escape("a b c d"); // "a%20b%20c%20d"
original = uri:unescape(escaped); // "a b c d"
于 2011-05-21T02:44:30.140 回答