不知道发生了什么事。当我执行以下代码时...它运行良好...但它产生了错误。如果我将以下内容粘贴到浏览器地址栏中并点击它,我会得到一个 URL。如果我通过 KRL http:get 输入相同的 URL,我会得到一个完全不同的 URL。
“http://tinyurl.com/api-create.php?url=http://insideaf.blogspot.com”
在浏览器中我自己得到: http://tinyurl.com/6j7qucx
当通过 http:get 运行时我得到: http://tinyurl.com/4fdtnoo
区别在于第二个,即通过 KRL http:get 运行的那个,会命中请求的站点,但它会附加一个“/&”到请求的末尾。无论我在哪个网站上,它都会这样做。如果我访问 www.google.com,它会返回一个 tinyurl,结果为 www.google.com/& with 给我一个错误。我传递给 http:get 方法的所有站点都会返回一个 &在最后。这是我的代码,以便您可以看到我自己不是无意中添加的。
myLocation = 事件:param("位置");
url2tiny = "http://tinyurl.com/api-create.php?url="+myLocation;
tinyresponse = http:get(url2tiny);
tinyurl = tinyurl.pick("$.content");
如果我console.log url2tiny,它看起来就像它应该的那样。看来当我将 url2tiny 传递给 http:get 时,它会自动添加 &在从tinyurl api 请求它之前到它的末尾。
对于解决此问题有什么想法吗?这似乎是 http:get 方法中的一个错误。如果我错了(我希望我是错的),请指出我正确的方向。
Not sure what is going on. When I perform the following code... it runs fine... but it is producing an error. If I paste the following into my browser address bar and hit it, I get one URL. If I put the same url through the KRL http:get, I get a completely different URL.
"http://tinyurl.com/api-create.php?url=http://insideaf.blogspot.com"
on my own in the browser I get: http://tinyurl.com/6j7qucx
when run through http:get I get: http://tinyurl.com/4fdtnoo
The difference is that the second one, the one run through the KRL http:get hits the requested site, but it appends a "/&" to the end of the request. It does this no matter what site I am on. If I am on www.google.com, it returns a tinyurl that results in www.google.com/& with gives me an error. All sites that I pass to the http:get method get returned with an & at the end. Here is my code, so that you can see that I am not accidentally adding it myself.
myLocation = event:param("location");
url2tiny = "http://tinyurl.com/api-create.php?url="+myLocation;
tinyresponse = http:get(url2tiny);
tinyurl = tinyurl.pick("$.content");
If I console.log the url2tiny, it looks exactly like it should. It appears that when I pass url2tiny to http:get, it is automatically adding the & to the end of it before it requests it from the tinyurl api.
Any ideas for workarounds to this issue? It appears to be a bug in the http:get method. If I am wrong (and I hope I am), please point me in the right direction.
发布评论
评论(1)
在这两种情况下,您的格式都略有偏差。 http:get 可以用作 pre 块中的表达式,但语法与在 action 块中使用它的方式不同。
实际上,您可以通过多种不同的方式提出此请求。传统的方法是通过数据源
DATASOURCE
另一种方法是您尝试的方式,它是通过 http:get 作为 pre 块中的表达式。作为函数调用,http:get 有 2 个必需参数和两个可选参数:
您的第一次尝试不包含参数。
tinyresponse = http:get(url2tiny)
第二次尝试将参数放置在错误的参数位置。
http:get("tinyurl.com/api-create.php";,{"url":myurl})
http:get (pre block)
第三种方法是使用 http:get 作为操作并自动引发事件
http:get (action)
以下是针对此页面执行这些规则的示例
In both cases, your format is just slightly off. http:get can be used as an expression in the pre block, but the syntax is different from the way that you use it in the action block.
There are actually a number of different ways that you could make this request. The traditional way is through a datasource
DATASOURCE
The other way is how you were trying and it is through http:get as an expression in the pre block. Called as a function, http:get has 2 required parameters and two optional parameters:
Your first attempt did not include the params.
tinyresponse = http:get(url2tiny)
The second attempt places the params in the wrong argument position.
http:get("tinyurl.com/api-create.php";,{"url":myurl})
http:get (pre block)
The third method is using http:get as an action and auto-raising an event
http:get (action)
Here is an example of these rules executing against this very page