【发布时间】:2017-10-31 08:20:06
【问题描述】:
我对 android-7.0-nougat (P8 Lite 2017) 有一个奇怪的行为。 以前的所有版本都没有问题。
为了控制 iTunes,我通过HttpURLConnection 发送消息。
我想知道为什么控件不适用于某些功能。 我通过 Wireshark 查看连接。
示例:(它如何与 Android
http://192.168.111.198:3689/databases/78/...&type=music&sort=album&query=(('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:32')+ 'daap.songalbumid:11777812807525111312')
Android 7 做了什么:
http://192.168.111.198:3689/databases/78/...&type=music&sort=album&query=((%27com.apple.itunes.mediakind:1%27,%27com.apple.itunes.mediakind:32%27)+ %27daap.songalbumid:11777812807525111312%27)
可以看到只有'变成了%27。
这里是代码:(重要部分)
String temp = String
.format(Locale.US,
"%s/databases/%d/containers/%d/items?session-id=%s&meta=dmap.itemname,dmap.itemid,daap.songvotecount,daap.songyear,daap.songgenre,daap.songartist,daap.songalbum,daap.songtime,daap.songuserrating,daap.songtracknumber,dmap.containeritemid&type=music&sort=album&query=(('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:32')+'daap.songalbumid:%s')",
session.getRequestBase(), session.databaseId, session.libraryId, session.sessionId, albumid);
byte[] raw = RequestHelper.request(temp, false, 10000);
public static byte[] request(String remoteUrl, boolean keepalive, int timeout) throws Exception {
byte[] buffer = new byte[1024];
URL url = new URL(remoteUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Viewer-Only-Client", "1");
connection.setRequestProperty("Client-Daap-Version", "3.11");
connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
if (!keepalive) {
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);
} else {
connection.setReadTimeout(0);
}
connection.connect();
if (connection.getResponseCode() >= HttpURLConnection.HTTP_UNAUTHORIZED)
throw new Exception("HTTP Error Response Code: " + connection.getResponseCode());
在调试器中,%27 始终不可见。
只有在connection.getResponseCode() 之后我才在 Wireshark 上看到这个。
【问题讨论】:
-
考虑到
'是一个保留的URL字符,它应该是百分比编码的:en.wikipedia.org/wiki/Percent-encoding。 -
告诉这个苹果!控制 iTunes 我!有!发送它。
-
我与 Apple 没有任何交易。显然,你知道。所以,你告诉他们他们的 URL 系统坏了,需要修复。
标签: android url special-characters httpurlconnection android-7.0-nougat