使用 URI 构建器构建 URL
Building URL using URI builder
编码URL-
https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select%20*%20where%20((A%20%3D%20201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
解码URL-
https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select * where ((A= 201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
在 URI 构建器中 URL 我们应该使用编码还是解码?
此外,给定的代码无效 :-
String xyz="1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU";
String X="201";
final String STUDENT_RECORD_URL="https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select*where";
final String Frag1 = "A";
final String Frag2 = "key";
Builder builder = Uri.parse(STUDENT_RECORD_URL).buildUpon();
builder.appendQueryParameter(Frag1,X);
builder.appendQueryParameter(Frag2,xyz);
String finalUri=builder.build().toString();
我认为您误解了查询参数。它们都应该是您 url 中的键值对。对于您的 url https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select * where ((A= 201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
,构建它看起来像:
final String STUDENT_RECORD_URL="https://spreadsheets.google.com/tq";
Builder builder = Uri.parse(STUDENT_RECORD_URL).buildUpon();
builder.appendQueryParameter("txq", "out:JSON");
builder.appendQueryParameter("tq", "select * where ((A= 201))");
builder.appendQueryParameter("key", "1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU");
String finalUri = builder.build().toString();
appendQueryParameter
方法将自动 url 编码您的参数。
编码URL-
https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select%20*%20where%20((A%20%3D%20201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
解码URL-
https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select * where ((A= 201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
在 URI 构建器中 URL 我们应该使用编码还是解码?
此外,给定的代码无效 :-
String xyz="1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU";
String X="201";
final String STUDENT_RECORD_URL="https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select*where";
final String Frag1 = "A";
final String Frag2 = "key";
Builder builder = Uri.parse(STUDENT_RECORD_URL).buildUpon();
builder.appendQueryParameter(Frag1,X);
builder.appendQueryParameter(Frag2,xyz);
String finalUri=builder.build().toString();
我认为您误解了查询参数。它们都应该是您 url 中的键值对。对于您的 url https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select * where ((A= 201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
,构建它看起来像:
final String STUDENT_RECORD_URL="https://spreadsheets.google.com/tq";
Builder builder = Uri.parse(STUDENT_RECORD_URL).buildUpon();
builder.appendQueryParameter("txq", "out:JSON");
builder.appendQueryParameter("tq", "select * where ((A= 201))");
builder.appendQueryParameter("key", "1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU");
String finalUri = builder.build().toString();
appendQueryParameter
方法将自动 url 编码您的参数。