Java:处理网络协议 [英] Java: handling webcal protocol

查看:140
本文介绍了Java:处理网络协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下载 - 甚至只是打开一个流 - 到位于webcal://www.somewhere.com/foo?etc = bar的日历。

I'm trying to download - or even just open a stream - to a calendar located at webcal://www.somewhere.com/foo?etc=bar.

当我这样做时,Java URL类抛出了未知协议:网络摄像头异常:

The Java URL class is throwing a "unknown protocol: webcal" exception when I do:

URL url = new URL("webcal://...");

我怎么能告诉URL类它应该只使用HTTP作为trasport协议,即使web资源也是如此位于webcal://协议后面的某个位置?

How can I tell the URL class that it should just use HTTP as trasport protocol even if the web resource is located somewhere behind a webcal:// protocol?

或者,无论如何,如何下载我的日历?

Or, in any case, how can I get my calendar downloaded?

请记住,如果我尝试用http:/替换webcal://,我正在呼叫的网络服务器不会提供日历服务/\".

Please, bear in mind that the web server I'm calling does not serve the calendar if I try to replace the "webcal://" with "http://".

推荐答案

webcal://是一个非官方的URI方案,请参阅Wikipedia 文章

The "webcal://" is an unofficial URI scheme, see Wikipedia article on it.

因此它可能代表一个或另一个后端实现 - 例如您正在调用的Web服务器可能正在使用任何提到的协议实现,例如 WebDAV ,< a href =https://en.wikipedia.org/wiki/CalDAV\"rel =nofollow> CalDAV 或 OpenDAV

As such it might stand for one or another back end implementation - e.g. the web server you are calling might be using any of the mentioned protocol implementations, such as WebDAV, CalDAV or OpenDAV

但是,如果您只想读取文件的内容,那么任何HTTP客户端都应该这样做,因为上面提到的协议基于HTTP。

However if all you want is to read the contents of the file, then any HTTP client should do the trick, because the above mentioned protocols are based on HTTP.

这是一个如何使用URL自己的机制来打开远程iCal的示例 HttpURLConnection

Here is an example on how to read a remote iCal using URL's own mechanism for opening HttpURLConnection :

    URL calendarURL = new URL("http://www.facebook.com/ical/b.php?uid=myUID&key=myKEY");
    URLConnection connection = calendarURL.openConnection();
    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    while (reader.ready()) {
        System.out.println(reader.readLine());
    }

如您所见,我已更改原始网址

As you can see I have changed the original URL from

webcal://www.facebook.com/ical/b.php?uid = MYUID& key = MYKEY

webcal://www.facebook.com/ical/b.php?uid=MYUID&key=MYKEY

to

http ://www.facebook.com/ical/b.php?uid = MYUID& key = MYKEY

,因为我们使用的是java.net。 URL,默认情况下,Java无法识别此协议。如果您要联系的Web服务器确实仅通过webcal提供内容://那么您可能需要使用适当的客户端(基于服务器使用的确切协议实现)。例如,有许多框架提供WebDAV客户端功能,例如 JackRabbit 沙丁鱼等。

, because we use a java.net.URL and by default Java does not recognize this protocol. If indeed the web server you want to contact only serves the content over webcal:// then you might need to use the appropriate client (based on the exact protocol implementation the server uses). For example there are a multitude of frameworks that provide WebDAV client capabilities, such as JackRabbit, Sardine, etc.

如果您提供更多信息关于我们可以进一步挖掘的服务器类型。

If you provide more information on the type of server we can dig further.

这篇关于Java:处理网络协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆