我正在尝试从 Shoutcast 服务器获取歌曲名称。所以,我的想法是在 Shoutcast 服务器的 7.html 页面上做一些正则表达式,但是我无法获得简单的 HttpGet 请求来接收 7.html 页面。我究竟做错了什么?
如果我从链接中删除端口号,HttpGet 将毫无问题地运行,但我不会得到我的结果。
private class GetTrackInfo extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... Urls) {
String url = urls[0];
if(!url.contains("http://")) url = "http://" + url;
url = url + "/7.html";
HttpParams params = new BasicHttpParams();
HttpClient httpclient = new DefaultHttpClient(params);
HttpGet http = new HttpGet(url);
HttpResponse response = null;
try {
response = httpclient.execute(http);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
response.getEntity().writeTo(out);
} catch (IOException e) {
e.printStackTrace();
}
String res = out.toString();
return res;
}
@Override
protected void onPostExecute(String result) {
Log.i("GetTrack", "Track result: " + result);
String[] results = result.split(",");
String track = results[results.length-1];
fplayer.setStreamInfoTxt(track);
}
}
作为一个错误,我得到:
01-29 23:28:10.461: W/System.err(962): org.Apache.http.client.ClientProtocolException 01-29 23:28:10.471: W/System.err(962): 在 org.Apache。 http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.Java:557) 01-29 23:28:10.471: W/System.err(962): at org.Apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient .Java:487) 01-29 23:28:10.471: W/System.err(962): 在 org.Apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.Java:465) 01-29 23:28 :10.471: W/System.err(962): 在 com.imsgroups.exyuradio.services.PlayerService$GetTrackInfo.doInBackground(PlayerService.Java:257) 01-29 23:28:10.471: W/System.err(962) : 在 com.imsgroups.exyuradio.services.PlayerService$GetTrackInfo.doInBackground(PlayerService.Java:1) 01-29 23:28:10.481: W/System.err(962): 在 Android.os.AsyncTask$2.call( AsyncTask.Java:185) 01-29 23:28:10.481: W/System.err(962): 在 Java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.Java:305) 01-29 23:28:10.491: W/ System.err(962): 在 Java.util.concurrent.FutureTask.run(FutureTask.Java:137) 01-29 23:28:10.491: W/System.err(962): 在 Java.util.concurrent.ThreadPoolExecutor .runWorker(ThreadPoolExecutor.Java:1068) 01-29 23:28:10.491: W/System.err(962): 在 Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:561) 01-29 23 :28:10.491:W / System.err(962):在Java.lang.Thread.run(Thread.Java:1096)01-29 23:28:10.491:W / System.err(962):引起: org.Apache.http.ProtocolException:服务器未能响应有效的 HTTP 响应 01-29 23:28:10.511:W/System.err(962):在 org.Apache.http.impl.conn.DefaultResponseParser.parseHead (DefaultResponseParser.Java:93) 01-29 23:28:10。511: W/System.err(962): 在 org.Apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.Java:174) 01-29 23:28:10.511: W/System.err(962):在 org.Apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.Java:179) 01-29 23:28:10.511: W/System.err(962): 在 org.Apache.http.impl.conn.DefaultClientConnection。 receiveResponseHeader(DefaultClientConnection.Java:235) 01-29 23:28:10.522: W/System.err(962): at org.Apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.Java:259) 01-29 23:28:10.522: W/System.err(962): 在 org.Apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.Java:279) 01-29 23:28:10.522: W/System.err(962 ): 在 org.Apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.Java:121) 01-29 23:28:10.522: W/System.err(962): 在 org.Apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.Java:410) 01-29 23:28:10.541: W/System.err(962):在 org.Apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.Java:555)