api return 404
In my android application, when I try to parse the spotify web api, the page return a 404. The URL seems ok to me (http://ws.spotify.com/search/1/album.xml?q=album:'Meteora'+artist:'Linkin Park'), but returns 404.
Here is my code :
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());
Here is the error :
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)
...
Alright, my bad. My URL wasn't encoded in UTF8, so Spotify responded with a 404. Solution is to parse the album name and artist that way :
String myURL = "album:'" + albumName + "'+artist:'" +artistName +"'";
url = new URL("http://ws.spotify.com/search/1/album.xml?q=" + URLEncoder.encode(myURL,"UTF-8"));
and then do whatever we want with this URL.
链接地址: http://www.djcxy.com/p/55568.html上一篇: Spotify预览API搜索曲目和专辑
下一篇: api返回404