Hey, I want to create a simple Android application to love the last track. I get a song from user.getRecentTrack and send the data and session key to my method, but there is an error: "The target server could not respond." Sometimes error 3 from the lastfm: track.love method also occurs: "Invalid Method - there is no method with this name in this package." This is my Http request for track.love
HttpClient client = new DefaultHttpClient();
String postURL = "http://ws.audioscrobbler.com/2.0/";;
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
String signatur = makeTrackLoveSignatur(artist, title, key);
params.add(new BasicNameValuePair("method", "track.love"));
params.add(new BasicNameValuePair("track", title));
params.add(new BasicNameValuePair("artist", artist));
params.add(new BasicNameValuePair("api_key", api_key));
params.add(new BasicNameValuePair("api_sig", signatur));
params.add(new BasicNameValuePair("sk", key));
params.add(new BasicNameValuePair("format", "json"));
UrlEncodedFormEntity ent =
new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
InputStream data = responsePOST.getEntity().getContent();
I also implemented the conversion of the InputStream method to String:
BufferedReader reader = new BufferedReader(
new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Output"+sb.toString());
return sb.toString();
What is the problem? Thank...
source
share