如何使用startAT在Firebase REST Query中使用url编码的字符串

时间:2015-06-23 05:26:53

标签: rest firebase

在我们的数据库中,我们有用作FireBase密钥的网址 这些键是url编码的形式字符串:

http%3A%2F%2Fblog%ZZexample%ZZcom%2F_Test_Blog_2015_06

GET请求返回空:

curl 'https://mydb.firebaseio.com/publishers/0000014d45a67fa3_4e93b3f/sites/0000014d45b0dc08_20173d1/pages.json?auth=authstringredacted;startAt="http%3A";orderBy="$key";limitToLast=1'

这会返回一个项目(注意" startat"参数差异):

curl 'https://mydb.firebaseio.com/publishers/0000014d45a67fa3_4e93b3f/sites/0000014d45b0dc08_20173d1/pages.json?auth=authstringredacted;startAt="http";orderBy="$key";limitToLast=1'

起初我认为这可能是由于查询参数的url编码,但使用这些不能正常工作:

startAt="http%253A"

startAt="http:";orderBy="$key";limitToLast=1'

我有一个http请求客户端,因此它不会对查询参数进行编码,而且它也不起作用。

我知道依赖于REST接口上的非url编码查询字符串看起来很奇怪,但Firebase依赖于查询arg值是有效的JSON。注意额外的""围绕查询arg值。

是否有解决方法使查询有效?

另一种方法是添加另一个表,将URL键映射到没有编码问题的唯一ID。

1 个答案:

答案 0 :(得分:3)

看起来您可以使用双倍百分比来编码百分比。但是您必须对它们进行网址编码,因此您可以使用%%而不是%来代替每个%25%25

因此,对于您的示例,此URL应该可以解决问题: https://mydb.firebaseio.com/publishers/0000014d45a67fa3_4e93b3f/sites/0000014d45b0dc08_20173d1/pages.json?auth=authstringredacted;startAt="http%25%253A%25%252F%25%252Fblog%25%25ZZexample%25%25ZZcom%25%252F_Test_Blog_2015_06";orderBy="$key";limitToLast=1