我正在制作应用程序来收听在线广播。所以我发送了一个HTTPS无线电网站。hplayRadioStream("https://radio.itechnepal.com/pathibhara/stream");
所以我尝试使用以下代码访问输入流:
private static void hplayRadioStream(String spec) throws MalformedURLException, IOException, JavaLayerException {
try{
URL url= new URL(spec);
HttpsURLConnection huc= (HttpsURLConnection) url.openConnection();
InputStream response= huc.getInputStream();
Player player= new Player(response);
player.play();
}
catch(Exception e){
System.out.println(e);
}
}
它给出403禁止错误。所以我尝试使用SSLSocketFactory使用以下代码实现这个:
private static void hplayRadioStream(String spec) throws MalformedURLException, IOException, JavaLayerException {
try{
Security.addProvider ( new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty ("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
SSLSocketFactory factory =
(SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket =
(SSLSocket)factory.createSocket(spec, 443);
socket.startHandshake();
InputStream response= socket.getInputStream();
Player player= new Player(response);
player.play();
}
catch(Exception e){
System.out.println(e);
}
}
这会产生UnknownHostException。因此,当我尝试使用“nslookup”,“tracert”和“ping”访问其IP地址时,他们无法找到域或显示不存在的域。但如果它不存在那么为什么原始网站从这里播放相同的流:http://www.pathibharafm.org/。甚至浏览器在下一个选项卡中粘贴流链接时显示403禁止消息。请帮忙。