URI Builder - 构建查询字符串?

时间:2014-10-13 19:15:45

标签: android uri uribuilder

我正在尝试构建一个String / URI来访问API。 API采用句子参数。现在我尝试这样做的原因如下:

//params[0] is a String such as "You will be a hero"
Uri.Builder builder = new Uri.Builder();
builder.scheme("https").authority("yoda.p.mashape.com/yoda").appendQueryParameter("sentence", params[0]);
Log.v("STRING TEST", builder.build().toString());

这只是我最好的尝试,并没有按我的意愿行事。目前输出:

https://yoda.p.mashape.com%2Fyoda?sentence=you%20will%20be%20a%20hero

我正在寻找一种构建如下所示URI的方法:

https://yoda.p.mashape.com/yoda?sentence=you+will+be+a+hero

任何帮助将不胜感激。非常感谢!

1 个答案:

答案 0 :(得分:1)

要修复%2f,请在此处查看:Uri Builder in android - '/' replaced by '%2F' and ":" is replaced by "%3A"并修复%20,尝试将空格替换为+,然后再将其添加到构建器中。