如何在使用startAT的Firebase REST查询中使用url编码的字符串 [英] How to use url encoded string in Firebase REST Query using startAT

查看:116
本文介绍了如何在使用startAT的Firebase REST查询中使用url编码的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

A 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=\"$\"\"; limitToLast=1'

起初我以为这可能是由于查询参数的url编码造成的,但是使用它们也不起作用:

  startAt =http%253A

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

一个http请求客户端,所以它不会编码查询参数,它也不起作用。

我知道,它看起来很奇怪,依赖于非网址编码的查询字符串在REST接口上,但Firebase依赖于查询参数值是有效的JSON。请注意查询参数值附近的多余。



是否有解决方法可以使查询工作?另一种方法是添加另一个表这个URL关键字是唯一没有编码问题的id。

解决方案

看起来你可以用double-percents来编码百分之一。但是你必须对它们进行URL编码,所以不要用 %% 代替每个,你可以使用

$ b p
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


In our database we have URLs that are used as FireBase keys.
These keys are url encoded strings of the form:

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

A GET request returns empty:

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

Whereas this returns an item (note the "startat" parameter difference):

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

At first I thought it might be due to the url encoding of the query args, but using these don't work either:

startAt="http%253A"

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

I have a http request client so that it doesn't encode the query args, and it also doesn't work.

I am aware that it looks weird to depend on non url encoded query strings on a REST interface but Firebase depends on the query arg values being valid JSON. Note the extra "" around the query arg values.

Is there a workaround that makes the queries work?

The other alternative is to add another table that maps the URL keys to unique ids that do not have the encoding problem.

解决方案

It looks like you can use double-percents to encode a percent. But you have to URL-encode them, so instead of using %% in place of each %, you would use %25%25.

So for your example, this URL should do the trick: 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

这篇关于如何在使用startAT的Firebase REST查询中使用url编码的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆