[英]HTTP Post Request: target server failed to response
Hey, I want to build a simple android app for loving the recent track. 嘿,我想建立一个简单的Android应用程序,爱上最近的轨道。 I receive the song with user.getRecentTrack and send the data and session key to my method but there is an error: "The target server failed to response."
我收到了user.getRecentTrack的歌曲,并将数据和会话密钥发送到我的方法,但是有一个错误:“目标服务器无法响应。” Sometimes, there is also Error 3 from the lastfm method: track.love: "Invalid Method - No method with that name in this package".
有时,lastfm方法也有错误3:track.love:“无效方法 - 此包中没有使用该名称的方法”。 This is my Http Post Request for track.love
这是我对track.love的 Http Post请求
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 implemented also a convert InputStream to String method: 我还实现了一个转换InputStream到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's the problem? 有什么问题? Thanks...
谢谢...
Try adding the Content-type header: 尝试添加Content-type标头:
post.addHeader("Content-type", "application/x-www-form-urlencoded");
Here's a similar question in python . 这是python中的一个类似问题 。
Have you tried asking in XML, not in JSON? 您是否尝试过使用XML而不是JSON? It could be down or something .
它可能是失败的东西 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.