在我的android应用程序中,当我试图解析spotify web api时,页面返回404。这个网址对我来说似乎没问题(http://ws.spotify.com/search/1/album.xml?q=album:'Meteora'+artist:'Linkin Park'),但返回404。
下面是我的代码:
url = new URL("http://ws.spotify.com/search/1/album.xml?q=album:'" + albumName + "'+artist:'" +artistName +"'");
urlc = url.openConnection();
urlc.addRequestProperty("User-Agent", userAgent);
Log.v(TAG_SPOTIFY, "User-agent set: " + userAgent);
return this.parseSpotifyURI(urlc.getInputStream());下面是错误:
06-20 16:51:00.846: W/System.err(4962): java.io.FileNotFoundException: http://ws.spotify.com/search/1/album.xml?q=album:'Meteora'+artist:'Linkin Park'
06-20 16:51:00.846: W/System.err(4962): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
06-20 16:51:00.846: W/System.err(4962): at com.micky.scanthings.music.ParseMusic.getSpotifyURI(ParseMusic.java:489)
...发布于 2012-06-21 00:17:29
好吧,是我的错。我的网址不是用UTF8编码的,所以Spotify的回应是404。解决方案是以这种方式解析专辑名称和艺术家:
String myURL = "album:'" + albumName + "'+artist:'" +artistName +"'";
url = new URL("http://ws.spotify.com/search/1/album.xml?q=" + URLEncoder.encode(myURL,"UTF-8"));然后对这个URL做任何我们想做的事情。
https://stackoverflow.com/questions/11123499
复制相似问题